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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.