BookmarkSubscribeRSS Feed
DangIT
Fluorite | Level 6

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

5 REPLIES 5
LinusH
Tourmaline | Level 20

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

Data never sleeps
data_null__
Jade | Level 19

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.

DangIT
Fluorite | Level 6

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;

data_null__
Jade | Level 19

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.

ballardw
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 5 replies
  • 874 views
  • 0 likes
  • 4 in conversation