BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi SAS users,

I have a question regarding reading multiple files. I have a folder containing 13 text files with filenames starting with a number (ex. 1.txt, 2.txt, 3.txt....) and they all have the same variables but different data values. I'd like to use the files 1 and 2, 2 and 3, 3 and 4, 4 and 5, and so forth in successive executions such that I can stack the descriptive statistics generated for 1 and 2, 2 and 3, 3 and 4....into one large file. So, each combination (eg. 1.txt, 2.txt; 2.txt, 3.txt, etc) will be given an id followed by the descriptive statistics. Can anybody offer some suggestions? Thanks!
2 REPLIES 2
ballardw
Super User
I'd be tempted to start with a filename like:
Filename mydata '\*.txt'; /*expanding path to your location and the appropriate wildcard for your system. This will attempt to read ALL files with TXT extension in the location. */

Then in the data step have :
LENGHT FILEVARNAME $ 80 ; /*long enough to include entire path and file names above. */
and add the option FILENAME= Filevarname on the INFILE statement used to read the data.

This reads all of the text data files with a temporary variable that is not added to your data named FILEVARNAME (or what ever you'd like to call it) that can then be parsed using string functions to identify your original files and add additional variables describing the groups you want to look at later. With out knowing which summary statistics you want cant go much further but CLASS statements in PROC SUMMARY with attention to _type_ in output might get you started.
deleted_user
Not applicable
Thanks much ballardw.

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1203 views
  • 0 likes
  • 2 in conversation