DATA Step, Macro, Functions and more

Combine multiple datasets into one previous month dataset

Regular Contributor
Posts: 179

Combine multiple datasets into one previous month dataset

%macro combine;


data lm_all;


%do i=1 %to 24;

   lossmit.loss_mit_settlements_&last_month.*/ (keep=loan_number type actual_completion_date)









This code at one time pulled a dataset that already compiled loss_mit settlements into one dataset for the previous month

(ie       loss_mit_settlements_20160201




was automatically compiled into one previous month dataset called loss_mit_settlements_201602


The data no longer offers this. It separates each data set individually. Is there a way to use the same macro to compile all daily datasets into one previous month file to essentially mirror what I used to have when the dataset was combine already.

Super User
Posts: 6,785

Re: Combine multiple datasets into one previous month dataset

If either of these would be appropriate, they are available:


data im_all;

set lossmit.loss_mit_settlements_2016: (keep=loan_number type actual_completion_date);



data im_all;

set lossmit.loss_mit_settlements_201602: (keep=loan_number type actual_completion_date);


Super User
Posts: 13,583

Re: Combine multiple datasets into one previous month dataset

You would have to provide more details about the names of the data sets involved.

If this is part of an input proceess you might describe the incoming original datasets and how you read them.


The way your current example macro is displayed you would read a single dataset 24 times as you are not changing the name at all.


Note that if you have similar dataset names you can use a list modifier : to get all of the data sets that start with the same characters. For example if your datasets are loss_mit_settlements_Feb_01 loss_mit_settlements_Feb_02 loss_mit_settlements_Feb_03

then you could use

Set loss_mit_settlements_Feb_: ;

To read all of the sets that start with loss_mit_settlements_Feb_

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation