BookmarkSubscribeRSS Feed
raju23
Calcite | Level 5

Hi everyone.
I have a folder that contain mutiple text documents, placed in subfolders.
Is there a way of importing the file names of these files as a string into a dataset?
I have found some examples round the internet and in SAS community but they dont seem to be working.

Files are in .txt,.dat,.tx,.csv and pgp format.

 

Thanks,

2 REPLIES 2
Reeza
Super User

There's lots of examples across the web as you've indicated.

 

Here's one that fully documented and that you can change as desired. You'll need to actually remove code because you don't care about the extension, but it should get you started. 

 

This assumes you're on Windows and not in a lockdown system.

 

http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#n0js70lrkxo6uvn1f...

ChrisNZ
Tourmaline | Level 20

Here is another option.

You may have to alter th


filename DIR pipe "dir ""c:\temp\*.sas"" /s/q " ;
data FILES;  
  infile DIR pad;
  input X $256.;    
  length PATH FILENAME $256;
  retain PATH ;
  if index(X,'Directory of') then PATH=substr(X,14);
  else if char(X,3)='/' and not index(X,'<DIR>') then do;
    TOPDIR  =catx('\',scan(PATH,1,'\'),scan(PATH,2,'\'),scan(PATH,3,'\'));  
    FILENAME=substr(X,65);
    DATE    =input(scan(X,1,' '),?? ddmmyy10.);
    SIZE    =input(scan(X,4,' '),?? comma20.);
    OWNER   =substr(X,42,23);
    output;
  end;
  format DATE date9. SIZE comma20.0;
  *drop X;
run;      

e way the line is parsed as Windows changes the file description line depending on its coonfiguration.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2720 views
  • 0 likes
  • 3 in conversation