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';
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
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
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';
@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';
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.