02-09-2017 06:34 AM
Me, the newbe, has created a macro to read in some csv files. It works but I think the code can be smarter since now I do this manually for something like 30 files which are all located in the same folder. Here an example for reading in 5 files.
the code in SAS EG:
PROC IMPORT OUT=SAS_TMP.&infile
datafile = "\\DWCPMCP\Data\01_INPUTDOCS\&infile..csv"
My is, can I make this code less manually intensive? There are more files coming in. Can I import the whole folder in one time instead of typing them out?
02-09-2017 06:59 AM
Its a good idea to do a search before posting a question. There are literaly hundreds of posts on this topic:
You don't need macro, you can do it in a datastep and use wildcards:
All you have to remember is proper CSV files have headers, so you need to jump one row per file.
02-09-2017 09:00 AM
I would recommend the methods here. You may need some modification to start at line 6.
Note that proc import guesses types so as the number of files gets larger it's more likely that you'll get inconsistent data types, ie a VAR is char in one dataset and numeric in another.
Using method above requires you explicitly specify it, once.
02-09-2017 09:01 AM
And best of all the doc has exactly your example
02-09-2017 11:24 AM
* create three csvs; dm "dexport sashelp.cars'd:\csv\cars.csv' replace"; dm "dexport sashelp.class'd:\csv\class.csv' replace"; dm "dexport sashelp.classfit'd:\csv\classfit.csv' replace"; * create three sas datsets; %symdel fyl; * just in case it exists; data _null_; do csv="classfit","class","cars"; fyl=catx(' ',"dm 'dimport",cats('"d:\csv\',csv,'.csv"'),csv,"replace';"); call execute(fyl); end; run;quit; NOTE: WORK.CLASSFIT data set was successfully created. NOTE: The data set WORK.CLASSFIT has 19 observations and 10 variables. NOTE: WORK.CLASS data set was successfully created. NOTE: The data set WORK.CLASS has 19 observations and 5 variables. NOTE: WORK.CARS data set was successfully created. NOTE: The data set WORK.CARS has 428 observations and 15 variables.
03-21-2018 01:23 PM
03-21-2018 10:42 PM
03-22-2018 04:20 AM
Please start a new post with your question.
It's sometimes better to tell us what you have and what you need - and only then tell us what you've already tried. You've got a lot of experienced people in this forum and it's sometimes worth to give the big picture as then you might get solution approaches you haven't even thought about.