- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;