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';
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.