I'm writing a code that imports lots of CSVs from the same folder, and then names them corresponding to the folder name (as the files are date-specific). I've tried a couple of things but was hoping for some input. This is one of the initial pieces of code:
PROC IMPORT DATAFILE='X://Projects/SAS/CSVs/_2019_05_16/0_C.csv' REPLACE DBMS=CSV OUT=Data._2019_05_16_T0; GETNAMES=YES; guessingrows=max; RUN;
Here's the sort of idea I was hoping to have, but obviously it's not working currently:
folder_reference=_2019_05_16; proc import datafile='X://Projects/SAS/CSVs/'&folder_reference&'/0_C.csv' replace DMBS=CSV out=Data.folder_reference&_T0 getnames=yes; guessingrows=max; run;
Do I have to put it in a macro format? I've tried to keep macro usage to a minimum in this code as those less fluent in SAS need to use this code too.
Thanks
Yes you could use macro language code, as the way you wrote the code will not work.
%let folder_reference=_2019_05_16;
proc import datafile="X://Projects/SAS/CSVs/&folder_reference/0_C.csv"
replace DMBS=CSV out=Data.&folder_reference._T0
getnames=yes;
guessingrows=max;
run;
Yes you could use macro language code, as the way you wrote the code will not work.
%let folder_reference=_2019_05_16;
proc import datafile="X://Projects/SAS/CSVs/&folder_reference/0_C.csv"
replace DMBS=CSV out=Data.&folder_reference._T0
getnames=yes;
guessingrows=max;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.