BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
apple
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

WHERE just want a valid boolean expression.

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

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

WHERE just want a valid boolean expression.

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

Jagadishkatam
Amethyst | Level 16

Alternative code,

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

Thanks,

jag

Thanks,
Jag
KarthikSrivasthav
Calcite | Level 5

Alternately u can use:

Data want;

set have;

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

where y=1;

run;

yaswanthj
Calcite | Level 5

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

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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