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!
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.
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?
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.