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

Hi,

 

This is driving me crazy as, this is too simple, but I may be too tired to see what is wrong.

 

In the code below, I have a snippet from a data step. When "LnMonthsToFinalStepCount " is missing, then instead of "Step_indicator = 'Never Step', I keep getting 'Finished Stepping'. What am I missing?

 

Thank you for your help!

 

Code:

        length Step_Indicator $20;
        if LnMonthsToFinalStepCount >= 0 then
            Step_Indicator = 'Currently Stepping';
        else if LnMonthsToFinalStepCount < 0 then
            Step_Indicator = 'Finished Stepping';
        else
            Step_Indicator = 'Never Step';

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

in sas sort sequence . (missing) is smaller than 0, that's the reason

 

therefore when  LnMonthsToFinalStepCount  is missing the statement if LnMonthsToFinalStepCount < 0  evaluates to true

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

in sas sort sequence . (missing) is smaller than 0, that's the reason

 

therefore when  LnMonthsToFinalStepCount  is missing the statement if LnMonthsToFinalStepCount < 0  evaluates to true

asimraja
Fluorite | Level 6
Thank you very much!
novinosrin
Tourmaline | Level 20

if you want else statement to execute, you would have to change the code to

 

Code:

        length Step_Indicator $20;
        if LnMonthsToFinalStepCount >= 0 then
            Step_Indicator = 'Currently Stepping';
        else if not missing(LnMonthsToFinalStepCount ) and  LnMonthsToFinalStepCount < 0 and  then 
            Step_Indicator = 'Finished Stepping';
        else 
            Step_Indicator = 'Never Step';

ballardw
Super User

 


@novinosrin wrote:

if you want else statement to execute, you would have to change the code to

 

Code:

        length Step_Indicator $20;
        if LnMonthsToFinalStepCount >= 0 then
            Step_Indicator = 'Currently Stepping';
        else if not missing(LnMonthsToFinalStepCount ) and  LnMonthsToFinalStepCount < 0 and  then 
            Step_Indicator = 'Finished Stepping';
        else 
            Step_Indicator = 'Never Step';



Shorter

if LnMonthsToFinalStepCount >= 0 then
            Step_Indicator = 'Currently Stepping';
        else if . < LnMonthsToFinalStepCount < 0 then
            Step_Indicator = 'Finished Stepping';
        else
            Step_Indicator = 'Never Step';

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1534 views
  • 0 likes
  • 3 in conversation