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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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