BookmarkSubscribeRSS Feed
GN0001
Barite | Level 11

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

Blue Blue
15 REPLIES 15
SASKiwi
PROC Star

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);
GN0001
Barite | Level 11

Hello,

It is a case statement and I can't use where.

Respectfully,

blue blue

Blue Blue
SASKiwi
PROC Star

@GN0001 - I'm suggesting you use a WHERE clause instead of CASE, not both together.

ChrisNZ
Tourmaline | Level 20

Missing values are the smallest in tests, so one way to rewrite your test is:

when ( . < RATE < 0.25 )

 

djh
Fluorite | Level 6 djh
Fluorite | Level 6
Set options missing='', then output missing value will be displayed by blank
GN0001
Barite | Level 11

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

Blue Blue
djh
Fluorite | Level 6 djh
Fluorite | Level 6
The missing numeric variable is represented by a dat(.) in data like below, see more  Working with Missing Values
djh_0-1625285921867.png

 

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 )
 
GN0001
Barite | Level 11
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
Blue Blue
djh
Fluorite | Level 6 djh
Fluorite | Level 6

 

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  is numberic. 

Try to change these result with same type. 

 

 

djh
Fluorite | Level 6 djh
Fluorite | Level 6
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 

Patrick
Opal | Level 21

@djh 

Always formulate an ELSE case to avoid below SAS Note. 

Patrick_1-1625297536509.png

 

Even though it's just a note always formulating an ELSE condition is just good practice.

 

djh
Fluorite | Level 6 djh
Fluorite | Level 6

Thanks for point this

Kurt_Bremser
Super User

@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:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

ChrisNZ
Tourmaline | Level 20

The syntax for a WHERE statement a WHEN clause are the same for this test.

where . < RATE < 0.25 

You should try by yourself.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 15 replies
  • 2385 views
  • 8 likes
  • 6 in conversation