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

See the following code:

 

proc import datafile="c:\2\(not sure yet).csv"
out=sas_1.really_want_this_data
dbms=csv
replace;
getnames=no;
guessingrows=max;
run;

Is there any way of asking SAS to simply grab the .csv file in C:\2\, and use whatever name it has, since I don't yet know the name of that file (or the name changes all the time)?

 

It is the one and only file in C:\2\.

 

Thanks much!

 

Nicholas Kormanik

 

 

 
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Asterisks function as a wildcard. Not sure if you need the extension though or not. 

/file/demo/*.CSV 

 

Note that it will read ALL CSV if there are multiple. 

View solution in original post

3 REPLIES 3
maguiremq
SAS Super FREQ

This should get you on the right path:

 

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=mcrolref&docsetTarget=n0j... 

 

It returns the file name. You might be able to store it as a macro variable and pull it based on that. Here's the code on the site:

%macro list_files(dir,ext);
  %local filrf rc did memcnt name i;
  %let rc=%sysfunc(filename(filrf,&dir));
  %let did=%sysfunc(dopen(&filrf));      

   %if &did eq 0 %then %do; 
    %put Directory &dir cannot be open or does not exist;
    %return;
  %end;

   %do i = 1 %to %sysfunc(dnum(&did));   

   %let name=%qsysfunc(dread(&did,&i));

      %if %qupcase(%qscan(&name,-1,.)) = %upcase(&ext) %then %do;
        %put &dir\&name;
      %end;
      %else %if %qscan(&name,2,.) = %then %do;        
        %list_files(&dir\&name,&ext)
      %end;

   %end;
   %let rc=%sysfunc(dclose(&did));
   %let rc=%sysfunc(filename(filrf));     

%mend list_files;
%list_files(c:\temp,sas)
Reeza
Super User

Asterisks function as a wildcard. Not sure if you need the extension though or not. 

/file/demo/*.CSV 

 

Note that it will read ALL CSV if there are multiple. 

NKormanik
Barite | Level 11
You da man, Reeza. Thanks, as always.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1118 views
  • 2 likes
  • 3 in conversation