BookmarkSubscribeRSS Feed
u_chandra
Calcite | Level 5

Hi there

 

My name is Chandra. I am not very good at SAS macro especially the looping part and resolving &&&. etc. Here is my problem statement.

 

Problem statement:

I have large number of raw data files (.dat files) stored in a folder in a SAS server. I need a macro that can read each of these rawdata file and create SAS data set for each raw data file and store them in a separate target folder in the SAS server. All these raw data files have same file layout structure. I need to automate this operation so that every week, the macro reads raw data files from the source folder and creates the corresponding SAS dataset and stores them in the target folder in the SAS server. For example, if there are 200 raw data files in a source folder, I want to read them and create 200 SAS datasets one for each rawdata file and save them in a separate target folder. I am not very good at constructing looping statement and also resolving && or &&& etc.  How do I do it?

 

I would highly appreciate your kind assistance in this regard.

 

Respectfully

 

Chandra

 

 

3 REPLIES 3
BrunoMueller
SAS Super FREQ

Chandra

 

To get a list of files you can use this macro http://www.sascommunity.org/wiki/Filelist_macro once you have the list of files I suggest you use a pattern very well described by @ChrisHemedinger in his blog entry Implement BY processing for your entire SAS program. Well in your case it is not about BY Group processing but more like doing something over a list of values.

 

Since you need a new library for each SAS data set, have a look at the SAS trick: get the LIBNAME statement to create folders for you

 

Bruno

LinusH
Tourmaline | Level 20
Creating 200+ files at different locations sounds like an non best practice. How do you maintain this, over time?
What is the the requirement?
Data never sleeps

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 2031 views
  • 3 likes
  • 4 in conversation