Hi Experts,
I am using below code to read multiple csv files but
data file_1;
infile "C:\Users\SAS\Desktop\shared\month_*.csv" dlm=',' firstobs=2;
input name $ dates:date9.;
format dates date9.;
run;
Please help me to skip the 1st row of each new file as each file has column header.
My csv files are month_1, month_2....month_4.
thanks
Or use a subsetting if:
data file_1;
infile "C:\Users\SAS\Desktop\shared\month_*.csv" dlm=',';
format name $10. dates date9.;
input name @;
if name ne "name";
input dates:date9.;
run;
Hello,
You can test if name="name" and drop the observation like this :
data file_1;
infile "C:\Users\SAS\Desktop\shared\month_*.csv" dlm=',';
format name $10. dates date9.;
input name @;
if name ="name" then delete;
else input dates:date9.;
run;
Or use a subsetting if:
data file_1;
infile "C:\Users\SAS\Desktop\shared\month_*.csv" dlm=',';
format name $10. dates date9.;
input name @;
if name ne "name";
input dates:date9.;
run;
SAS provides the EOV= option on the INFILE statement for giving the name of a variable that will indicate when you are changing files. But using that flag can get a little tricky.
It is actually a lot easier to use the FILENAME= option to name a variable that will contain the NAME of the file. Then you can just check if the name has changed. Make sure to define the variable as long enough that the names are not truncated.
data file_1;
length fname $256 ;
infile "C:\Users\SAS\Desktop\shared\month_*.csv" dsd truncover filename=fname;
input @;
if fname ne lag(fname) then input;
input name :$32. dates :date.;
format dates date9.;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.