BookmarkSubscribeRSS Feed
Aexor
Lapis Lazuli | Level 10

Hi Members,

 

Need help in one of topics.

Actually there is a requirement to read a external csv file from a folder of many CSV files. 

Suppose if I have 100 file in a folder , I have to read the 7th file only .

 

Can someone please suggest. What approach I should follow.

 

Thanks in advance.

 

Best regards 

 

 

5 REPLIES 5
PaigeMiller
Diamond | Level 26

7th according to what sorting? File name? File date? Some other sorting? Please explain further.

 

Also, do you need to do this reading of the 7th file once? Or will you have to read this 7th file many times with possibly other files added to or removed from the directory?

--
Paige Miller
Aexor
Lapis Lazuli | Level 10
files are created on daily basis. SO 7th in the 7th day file. Thanks for responding 🙂
PaigeMiller
Diamond | Level 26

@Aexor wrote:
files are created on daily basis. SO 7th in the 7th day file. Thanks for responding 🙂

This does not answer my question. 7th according to what sorting of the files?

--
Paige Miller
Tom
Super User Tom
Super User

How do you want to determine which file is the 7th?

Get the list of files.  Sort them in order.  Use the seventh one.

If you have the name of the file in a macro variable then use that macro variable to generate the code to access the file.

data want;
  infile "&fname" dsd firstobs=2 truncover;
  input var1 var2 ....

If you have the name of the file in a dataset variable then use that variable to tell SAS which file to read.

data want;
  set filelist (firstobs=7 obs=7);
  infile csv filevar=FNAME dsd firstobs=2 truncover end=eof;
  do while (not eof);
     input var1 var2 .... ;
     output;
  end;
run;
Aexor
Lapis Lazuli | Level 10
I will try

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 5 replies
  • 1461 views
  • 1 like
  • 3 in conversation