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.

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!

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.

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