Solved
Contributor
Posts: 66

# Macros help

Hi,

I have a macro set up that calculates the days inbetween two dates:

`%MACRO DAYS_DIFF(CURR_PER,PREV_PER);DATA A.TEST; SET A.PAYMENT_CHARGE_&TIMESTAMP; IF ME_S&CURR_PER='A' THEN DO;     IF ABS(INTCK('DAYS',CM&CURR_PER,PM&CURR_PER))<ABS(INTCK('DAYS',CM&CURR_PER,PM&PREV_PER))       THEN DAYS_DIFF_&CURR_PER=INTCK('DAYS',CM&CURR_PER,PM&CURR_PER);       ELSE DAYS_DIFF_&CURR_PER=INTCK('DAYS',CM&CURR_PER,PM&PREV_PER);END; IF ME_S&CURR_PER='S' AND CM&CURR_PER^=. THEN DAYS_DIFF_&CURR_PER=INTCK('DAYS',&CUTOFF_DATE,CM&CURR_PER); IF ME_S&CURR_PER='C' AND CM&CURR_PER^=. THEN DAYS_DIFF_&CURR_PER=INTCK('DAYS',&CUTOFF_DATE,ME_D&CURR_PER); RUN;%MEND;%DAYS_DIFF(1,2);%DAYS_DIFF(2,3);%DAYS_DIFF(3,4);%DAYS_DIFF(4,5);%DAYS_DIFF(5,6);%DAYS_DIFF(6,7);`

if i run this i will get an output of the last variable: DAYS_DIFF_6

i'm having troubles creating the final dataset that will combine all the DAYS_DIFF_1 - DAYS_DIFF_6 onto one dataset.

Accepted Solutions
Solution
‎02-02-2012 12:24 PM
Super User
Posts: 8,069

## Macros help

As Art says take the DATA , SET and RUN statements out of the macro so that it only generates the code to create the new variables. Then place the calls to the macro inside of a data step.

All Replies
PROC Star
Posts: 8,163

## Macros help

You didn't include any sample data, but it appears that you are re-creating a.test each time that you run the macro.  Don't you really want to create it at the beginning of your code and then simply update it each time you run your macro?

Solution
‎02-02-2012 12:24 PM
Super User
Posts: 8,069