Hi,
I have used the following code and macro to import mutliple csv files:
%let path = C:\;
filename folder "&path\ndakota0711";
libname c 'C:\Temp';
options validmemname=extend;
data county_list;
length Line 8 county_code $20;
list = dopen('folder');
do Line = 1 to dnum(List);
County_code = trim(dread(List,Line));
output;
end;
drop List Line;
run;
data nd0711;
set county_list end=final;
call symputx(cats('County_Code', _N_), trim(County_Code));
call symputx(cats('Name', _N_), trim(nliteral(substr(County_Code,1,min(32, length(County_Code)-4)))));
if final then call symputx(trim('Total'), _N_);
run;
%macro loop;
%do i = 1 %to &Total;
proc import datafile="&path\ndakota0711\&&County_Code&i"
out=c.&&name&i
dbms=csv
replace;
getnames=yes;
run;
%end;
%mend loop;
%loop
However, observations of the first variable "From" in all imported data sets are all trimmed or truncated (I have attached a screenshot of the output file). Can anyone help me with this.
Add the GUESSINGROWS=MAX option - it will take longer to run.
Or write a data step that explicitly defines the length and type.
Add the GUESSINGROWS=MAX option - it will take longer to run.
Or write a data step that explicitly defines the length and type.
When you run PROC IMPORT, check your log. It has the data step to import the code. Modify the lengths/types in that code to be what you want and then use that code to import the data.
This assumes all your data sets have the same type/format. If that's the case you can also follow the approach outlined here to import all at once into the same data set.
@abubakrayesh wrote:
Can you tell me where to insert the data step exactly? I am new to SAS and
not very comfortable with it yet. Thanks.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.