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!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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