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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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