DATA Step, Macro, Functions and more

Macros help

Accepted Solution Solved
Reply
Contributor
Posts: 66
Accepted Solution

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.

thanks for your help!


Accepted Solutions
Solution
‎02-02-2012 12:24 PM
Super User
Super User
Posts: 7,076

Macros help

Posted in reply to Danglytics

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.

View solution in original post


All Replies
PROC Star
Posts: 7,492

Macros help

Posted in reply to Danglytics

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
Super User
Posts: 7,076

Macros help

Posted in reply to Danglytics

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.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 133 views
  • 3 likes
  • 3 in conversation