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