Hi,
I have a macro that imports data for example:
%macro importdata(datafile) ;
<IMPORT DATA PROCEDURES...>
%Mend ;
I have 10 files with the same structure I would then run the macro on.
%importdata(file1) ;
%importdata(file2) ;
%importdata(file3) ;
....
In the end I would like to Append the files together as part of the macro.
Right now i am writing an additional datastep and manually scripting the dataset names from each macro output, i'm sure there is a better way.
Thank you for the help.
KD
Why don't you just include the append in the macro?
set name1-name10;
or
set name:;
or if the files all have the same data structure then read them from a concatenated or wild card FILEREF.
Yes, I was thinking of creating a blank template as a 'Master' table to append in the macro, and as I run each file import it will append to the master, but i'd have to be careful not to run the same file twice, or if there is an error in one of the file imports i'd probably have to rerun all of the imports again.
Unfortunately the file names are not sequentially structured to use Name: or name1-name10;
Name the data set in such a way that they make it easy to work with them. If you are combining them the individual names can be anything you like.
You don't mention the format of the data source files or how you are importing them. If using PROC IMPORT you may end up with different variable types for the same variable name which is going to cause problems as in failure to either Append or Set properly.
If you use filerefs instead of literal names then you add on to data_null_'s comment about creating dataset names in an easier fashion:
filename inset1 "<path and file for first data set>";
filename inset2 "<path and file for 2nd data set>";
and so on.
Or could be generated by reading a directory if things are clean enough.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.