BookmarkSubscribeRSS Feed
Kennychan0809
Calcite | Level 5

Hi All, 

 

I have a lot of excel files saved as date variable (i.e. "ABC 20181130.csv", "ABC 20181129.csv" ... etc) would like to import to SAS. Is there any way/code that SAS can read the date variable of the CSV files ?

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

How are you reading the csv files?  The simplest method is to take the filename when you put it in your import code.  The simplest method of this is in the datastep you use to import the data - you do use a datastep right:

data want;
  infile "c:/myfiles/*.csv" filename=filename dlm=",";
  length ...;
  input ...;
  informat ...;
  format ...;
  inname=filename;
run;

With this you can read 1 or more file - I just read all files with .csv extension in here - and get the filename information into a variable - you can process that variable to just get date out.

Jagadishkatam
Amethyst | Level 16

data work.testdata; infile '~path/ABC_20181130.csv' delimiter=',' ; input date yymmdd10. ; run;

or you could use

the

proc import datafile='~path/ABC 20181130.csv' dbms=csv replace;
run;

 

Thanks,
Jag
Reeza
Super User

You can also use the wildcard and use FILENAME to grab the file name from the file and parse out the date after the fact.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 2239 views
  • 0 likes
  • 4 in conversation