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
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.
This should get you on the right path:
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)
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.