BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Danglytics
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

2 REPLIES 2
art297
Opal | Level 21

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?

Tom
Super User Tom
Super User

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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