SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Join us for our biggest event of the year!

Four days of inspiring keynotes, product reveals, hands-on learning opportunities, deep-dive demos, and peer-led breakouts. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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