Subset data based on Numeric & Character Variables

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 75
Accepted Solution

Subset data based on Numeric & Character Variables

I have a dataset with

X: Character Variable

Y: Numeric Variable

I want to obtain the dataset with

X = a or b AND Y= 1

how do I write the code?

I understand that if I use "where" both variables must be of the same type (both character or both numeric).

Thank you


Accepted Solutions
Solution
‎12-22-2013 08:03 PM
Super User
Super User
Posts: 6,502

Re: Subset data based on Numeric & Character Variables

WHERE just want a valid boolean expression.

where (X = 'a' or X='b') AND (Y= 1) ;

View solution in original post


All Replies
Solution
‎12-22-2013 08:03 PM
Super User
Super User
Posts: 6,502

Re: Subset data based on Numeric & Character Variables

WHERE just want a valid boolean expression.

where (X = 'a' or X='b') AND (Y= 1) ;

Trusted Advisor
Posts: 1,131

Re: Subset data based on Numeric & Character Variables

Alternative code,

Where X in ('a','b') and Y=1;

Thanks,

jag

Thanks,
Jag
Contributor
Posts: 22

Re: Subset data based on Numeric & Character Variables

Alternately u can use:

Data want;

set have;

if x in ("a","b") then output;

where y=1;

run;

Contributor
Posts: 70

Re: Subset data based on Numeric & Character Variables

Hi ..

You can use any condition, which is provided by tom, jegadish and karthik. and also you can use proc sql to print the same result. where if you use the proc sql, it should take less time to execute the code rather than using data step. Thanks, yaswanth

proc sql;

select * from sasuser.admit

         where actlevel in ('HIGH','LOW')

         and fee gt 100;

             quit;


Thanks, yaswanth

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 593 views
  • 7 likes
  • 5 in conversation