*---This is create_csvs.sas in P:\irsmig . jgb, 4-10-07. Reads a set of xls files with co to co migration data by state and creates a single CSV file for inmig and another for outmig for the US. Adding code to handle naming glitch with Ohio 0304 outmigrants, 5-9-07. Running with 2005-06 data as recevied from IRS 8-2-2007 And on 8-11-07 running using replacement CD to process states 48 to 56 (TX to WY). And again on 8-19-08 with data for 06-07. And now on 8-25-08 we shall try reprocessing just the Texas data for earlier years--; ****! Rerunning 9-22-08 after changing the cell range on Excel export. Went from J8000 to J9500. We were losing data in Texas. Ange again on 10-23 to process 0405 year. ---*; filename pgm "p:\irsmig\create_csvs.sas"; %include 'P:\SAS Tools\sasmacro\dostates.sas'; %macro doit(state,stab); %global years; %macro dofile(io); %let io1=%substr(&io,1,1); filename out clear; filename out "p:\irsmig\co&years.US&io1..csv" ; ********* filename out "p:\irsmig\co0607TX&i01..csv"; *<=========================; %let extradir=%str(D:\co&years\co&years._excel); %if %sysfunc(fileexist(&extradir)) %then %let basedir=&extradir; %else %let basedir=%str(D:\co&years); %if &years ge 0506 and &years ne 9900 %then %let basedir=%str(D:); %let xfyears=&years; %*--years portion of Excel file name. They drop a 0 sometimes--; %if %index(0001_r 0102 0203,&years) %then %let xfyears=%substr(&years,2,3); %if &years=9900 %then %let xfyears=990; %if &years=0001_r %then %do; %if &io=in %then %let uscore=%str(-); %else %let uscore=%str(_); proc import datafile="D:\Co0001_r\Co0001r_excel\Co0001&io.r&uscore.excel\co001&stab&io1.r.xls" %end; %else %do; %local io1cd; %if &years=0304 and &state=39 and &io1=o %then %let io1cd=0; %else %let io1cd=&io1; *%--extra code to avoid this naming glitch for Ohio 03-04 out data; proc import datafile="&basedir\Co&years&io._Excel\co&xfyears&stab&io1cd..xls" %end; out=temp&stab&io1 replace; range='a9:j9500'; getnames=no; run; proc export data=temp&stab&io1 dbms=csv outfile="c:\temp\co&years&stab&io1..csv" replace; run; data _null_; infile "c:\temp\co&years&stab&io1..csv" firstobs=2; file out mod; input state $1-2; if state=',,' then stop; put _infile_; run; %mend dofile; %dofile(in); %dofile(out); %mend doit; options NOmprint; /* ============= Begin comment==================== %let years=0607; %dostates(01 02 04 05 06 08 09 10 11 12 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28); %dostates(29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46 47); %dostates(48 49 50 51 53 54 55 56); %let years=0506; %dostates(01 02 04 05 06 08 09 10 11 12 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46 47); *---get around bad data: do just al thru tn---; *---Here is the run against the replacement CD 8-11-07--; %dostates(48 49 50 51 53 54 55 56); ==================end comment =================== */ /* ============= Begin comment==================== %let years=0304; %dostates(n=51); %let years=0203; %dostates(n=51); %let years=0102; %dostates(n=51); %let years=0001_r; %dostates(n=51); %let years=9900; %dostates(n=51); ==================end comment =================== */ /* *---lets see if we can fix the problem with Texas for earlier years by just adding TX data to the end of the CSV files--; %let years=0304; %***dostates(48); %let years=0203; %dostates(48); %let years=0102; %dostates(48); %let years=0001_r; %dostates(48); options mprint; %let years=9900; %dostates(48); */ %let years=0405; %dostates(48);