BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rahul_SAS
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

3 REPLIES 3
gamotte
Rhodochrosite | Level 12

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;
Kurt_Bremser
Super User

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;
Tom
Super User Tom
Super User

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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 3880 views
  • 2 likes
  • 4 in conversation