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';

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 4 replies
  • 842 views
  • 0 likes
  • 3 in conversation