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
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?
@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?
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.