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 ?
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.
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;
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.