Macro Variables in if-then-else statements

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Macro Variables in if-then-else statements

Hi Everyone,

I'm trying to get a macro variable to store a certain value  based on the value of another variable.

In more detail, this is what I am trying to do:

1. I've created a variable called 'ACTUAL'

     - this variable is based on a tally of the number of days between 2 dates.

I used this code to create 'ACTUAL':

     data _null_;

        sdate='01jul15'd;

        edate='31aug15'd;

        actual=datdif(sdate, edate, 'act/act');

     run;

2. I want to use the output of 'ACTUAL' to create a macro variable depending on what the output of 'ACTUAL' is:

     for example:

     - if actual is <=31 then %let trmt_cap=3600     BUT

     - if actual is  >31 then %let trmt_cap=7200

STEP 2 is where I'm stuck but if there's a better way to do STEP 1 in order to achieve STEP 2 then that is ok by me.

Thanks for any and all help!

Eric


Accepted Solutions
Solution
‎07-10-2015 03:14 PM
Super User
Posts: 5,081

Re: Macro Variables in if-then-else statements

If you actually do want a macro variable, you would not have to change much:

     data _null_;

        sdate='01jul15'd;

        edate='31aug15'd;

        actual=datdif(sdate, edate, 'act/act');

        if actual <= 31 then call symputx('trmt_cap', '3600');

        else call symputx('trmt_cap', '7200');

     run;

View solution in original post


All Replies
Occasional Contributor
Posts: 9

Re: Macro Variables in if-then-else statements

Sorry, I might be using the term macro variable incorrectly. When I used that I was referring to the %let statement. Sorry for any confusion.

Solution
‎07-10-2015 03:14 PM
Super User
Posts: 5,081

Re: Macro Variables in if-then-else statements

If you actually do want a macro variable, you would not have to change much:

     data _null_;

        sdate='01jul15'd;

        edate='31aug15'd;

        actual=datdif(sdate, edate, 'act/act');

        if actual <= 31 then call symputx('trmt_cap', '3600');

        else call symputx('trmt_cap', '7200');

     run;

Occasional Contributor
Posts: 9

Re: Macro Variables in if-then-else statements

Yes perfect, that's exactly what I need.

Thanks so much!

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 231 views
  • 0 likes
  • 2 in conversation