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

Hi,

 

i have two variables in a data set and i want to see if the first variable has values which also exists in the other variable. For example:

 

Varone     Vartwo           Flag

 

 1               4                  0

2                7                   0

7                5                   1

4                8                   1

 

 

So, i want to check every single one of the values in Varone; if the value in Varone exists anywhere in variable Vartwo, then i want a flag value that says 1 and zero otherwise.

 

thanks

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

 

proc sql;
create table want as
select 
	*,
	varone in (select vartwo from have) as flag
from have;
quit;
PG

View solution in original post

4 REPLIES 4
thomp7050
Pyrite | Level 9

One method (there are many):

 

proc sql;
create table combvars as
select have.var1, have2.var2 
from have, have as have2
where have.var1 = have2.var2;
quit;
PGStats
Opal | Level 21

 

proc sql;
create table want as
select 
	*,
	varone in (select vartwo from have) as flag
from have;
quit;
PG
kiranv_
Rhodochrosite | Level 12

this should work

 

data abc;

input varone vartwo;

datalines;

1 4

2 7

7 5

4 8

;

run;

proc sql;

select varone, vartwo, case when varone=var1 then 1 else 0 end as flag

from

(select varone, vartwo from abc)a

full join

(select varone as var1

from abc

where varone in (select vartwo from abc))x

on a.varone =x.var1;

yocrachi
Fluorite | Level 6

Thank you all for your replies, i really appreciate it. It worked

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
  • 887 views
  • 4 likes
  • 4 in conversation