BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
millerm
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller
millerm
Fluorite | Level 6
Didn't realise it was that easy, my attempts were massively overcomplicated... Thanks!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 841 views
  • 1 like
  • 2 in conversation