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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.