Hello team,
I have missing values in SAS data set; when I run the code, extract the data into excel, I can see missing value are displayed by dot. How to filter them out:
case when (rate <0.25 and rate is not missing) Then 'do this'
Thanks!
blue blue
To filter your SAS dataset prior to exporting to Excel use the WHERE statement to exclude missing values:
where rate is not missing;
/* or */
where not missing(rate);
Hello,
It is a case statement and I can't use where.
Respectfully,
blue blue
@GN0001 - I'm suggesting you use a WHERE clause instead of CASE, not both together.
Missing values are the smallest in tests, so one way to rewrite your test is:
when ( . < RATE < 0.25 )
Hello,
The logic I placed might not be correct.
It is a case statement.
If I want to say that a rate is not equal to blank. How can I say it in SAS? I looked for it a lot and i couldn't find a method to take care of it.
Regards,
blue blue
To check that the rate is not equal blank, the rate must be a character.
I guess the rate in your date may be numeric.
As mentioned above , you can try
when ( . < RATE < 0.25 )
All the condition results shoule with same variable type.
proc sql;
select somking_status
,case smoking_status
when "Non-smoker" then "1"
when "Light (1-5)" then 2
end as smoking_cat
from sashelp.heart
;
quit;
The above code get same error, one result "1" is charactet but another result 2 is numberic.
Try to change these result with same type.
proc sql;
select Smoking_Status
,case Smoking_Status
when "Non-smoker" then 1
when "Light (1-5)" then 2
end as smoking_cat
from sashelp.heart
;
quit;
Update a typo and the right code
Always formulate an ELSE case to avoid below SAS Note.
Even though it's just a note always formulating an ELSE condition is just good practice.
Thanks for point this
@GN0001 wrote:
I handled with not missing(variable name)
I appreciate your help.
Now it gives another error as:
Error: Result of when clause 8 is not the same data types as the preceding results.
Thanks,
blue blue
Post the EXACT and COMPLETE log of your PROC SQL step. Use this button for posting the log:
The syntax for a WHERE statement a WHEN clause are the same for this test.
where . < RATE < 0.25
You should try by yourself.
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.