DATA Step, Macro, Functions and more

Data stacking/Append within Macro

Reply
Frequent Contributor
Posts: 81

Data stacking/Append within Macro

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

Super User
Posts: 5,255

Re: Data stacking/Append within Macro

Why don't you just include the append in the macro?

Data never sleeps
Respected Advisor
Posts: 3,777

Re: Data stacking/Append within 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.

Frequent Contributor
Posts: 81

Re: Data stacking/Append within Macro

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;

Respected Advisor
Posts: 3,777

Re: Data stacking/Append within Macro

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.

Super User
Posts: 10,483

Re: Data stacking/Append within Macro

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.

Ask a Question
Discussion stats
  • 5 replies
  • 261 views
  • 0 likes
  • 4 in conversation