BookmarkSubscribeRSS Feed
Raunak1
Calcite | Level 5
Hi

I have files named as A202401, A202402, A202303, A202301 and so on at same location. But I need any 3 files.
I want to create a macro which will help me to append all data sets into single sas data set. I want to store the files names in a list and then loop over the list to append files.
Your help is much appreciated.
2 REPLIES 2
Astounding
PROC Star

If these are the only file names that begin with "A2024" then the task is easy and does not require macros.  For example:

data want;
   set A2024: indsname = month;
run;

If some version of MONTH is already part of each data set,  you can skip the INDSNAME option.

ballardw
Super User

Have you verified that all the data sets you are thinking of using have the same variables? And that the variables are all of the same type and length?

 

I ask because the properties of the data may limit how you "append" data. And if the variables of the same name have different lengths additional steps may be needed to prevent loss of data. We have many cases of new users assuming their data is the same and finding out when they go to combine data sets that there are problems that will prevent any sort of appending.

 

If your problem is as as simple as you state you may just need a single macro variable.

 

%let listvar = A202401  A202303 A202308;

Data want;
   set &listvar;
run;

By same location I would expect in SAS terms that you have assigned a library to point to that location. Then the listvar above would have the datasets as libref.name instead of just the name.

libname mylib "<path>";

%let listvar = mylib.A202401 mylib.A202303 mylib.A202308;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 637 views
  • 0 likes
  • 3 in conversation