How to merge multiple csv files into 1 SAS file -
i started using sas 3 days ago , need merge ~50 csv files 1 sas dataset.
the 50 csv files have multiple variables 1 variable in common i.e. "region_id"
i've used sas enterprise guide drag , drop functionalities manual , took me half day upload , merge 47 csv files 1 sas file.
i wondering whether has more intelligent way of doing using base sas?
any advice , tips appreciated!
thank you!
example filenames: 2011census_b01_aust_short 2011census_b02a_aust_short 2011census_b02b_aust_short 2011census_b03_aust_short . . 2011census_xx_aust_short
i have more 50 csv files upload , merge.
the number , type of variables in csv file varies in each csv file. however, csv files have 1 common variable = "region_id"
example variables: region_id, tot_p_m, tot_p_f, tot_p_p, age_0_4_yr_f etc...
first, we'll need automated way import. below simple macro takes location of file , name of file inputs, , outputs dataset work directory. (i'd use concatenate function in excel create sas code 50 times). also, sorting make merge easier later.
%macro importcsv(location=,filename=); proc import datafile="&location./&filename..csv" out=&filename. dbms=csv replace; getnames=yes; run; proc sort data= &filename.; region_id; run; %mend; %importcsv(location = c:/desktop,filename = 2011census_b01_aust_short) . . .
then merge of data again. added ellipses because didn't want right out 50 times.
data merged; merge dataseta datasetb datasetc ... datasetax; region_id; run;
hope helps.
Comments
Post a Comment