sas macro - How to delete and import datasets dynamically in SAS? -


i have 4 comma separated files: mar2009.txt, mar2010.txt, mar2011.txt , mar2012.txt

i trying cleanse library , import datasets dynamically:

libname "c:\users\owner\desktop\sas\";  data a; // not step if not use the "do" becomes red in color = 2009 2012;  proc datasets library=my; delete mar.&i; run;  proc import out=my.mar.&i datafile="c:\users\owner\desktop\sas\mar.&i.txt" dbms=dlm replace; delimiter='2c'x; getnames=yes; datarow=2; run;  end; run; 

to answer question @ fundamental level, don't need "cleanse" dataset because reimporting it; automatically replaced.

you write macro import, so:

%macro import_myfile(i=); proc import file="...whatever...\mar&i.txt" out=mar_&i. dlm=',' replace; run; %mend import_myfile;  %import_myfile(i=2009); %import_myfile(i=2010); %import_myfile(i=2011); %import_myfile(i=2012); 

you write loop execute 2009 2012, it's not worth code if it's 4 runs. if have dynamic number execute, , values in dataset, way:

data data_torun; input filenum; datalines; 2009 2010 2011 2012 ;;;; run;  proc sql; select cats('%import_myfile(i=',filenum,')') :listtorun   separated ' '  data_torun; quit;  &listtorun.; *this become same 4 calls above; 

it typically better have data kept in dataset form rather in code when potentially change (even in loop). way store in text file , read in.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -