Help using Base SAS procedures

where statement when a variable equals another variable in different dataset

Accepted Solution Solved
Reply
Contributor
Posts: 65
Accepted Solution

where statement when a variable equals another variable in different dataset

Hello everyone,

I have two datasets, named Original and New. I want to create a subset of Original in which the values of the variable XXX are equal to variable YYY in dataset New.

I think it should be similar to where command but I don't know how to create such subset.

I appreciate your suggestions in advance.


Accepted Solutions
Solution
‎06-21-2015 01:58 AM
Super User
Posts: 17,963

Re: where statement when a variable equals another variable in different dataset

You end up needing a subquery:

WHERE VAR IN (SELECT VAR from TABLE2);

proc sql;

create table a as

select *

from table b

where id in (Select id from table c);

quit;

View solution in original post


All Replies
Solution
‎06-21-2015 01:58 AM
Super User
Posts: 17,963

Re: where statement when a variable equals another variable in different dataset

You end up needing a subquery:

WHERE VAR IN (SELECT VAR from TABLE2);

proc sql;

create table a as

select *

from table b

where id in (Select id from table c);

quit;

Contributor
Posts: 30

Re: where statement when a variable equals another variable in different dataset

Hi ,

You can use the  merge also for the desired result .

data want.

merge a (in = a )

          b (in = b) ;

by id  ;

if a and b ;

if xxx = yyy ;

run;

thanks

Contributor
Posts: 65

Re: where statement when a variable equals another variable in different dataset

thanks

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 306 views
  • 3 likes
  • 3 in conversation