DATA Step, Macro, Functions and more

Combine multiple datasets into one previous month dataset

Reply
Frequent Contributor
Posts: 141

Combine multiple datasets into one previous month dataset

%macro combine;

 

data lm_all;

  set

%do i=1 %to 24;

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

%end;

  ;

run;

 

%mend;

 

%combine;

 

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

           loss_mit_settlements_20160202

loss_mit_settlements_20160203  

 

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: 5,498

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);

run;

 

data im_all;

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

run;

Super User
Posts: 11,343

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
  • 241 views
  • 0 likes
  • 3 in conversation