BookmarkSubscribeRSS Feed
m1986MM
Obsidian | Level 7

Hi everyone, 

Because I could not find my question amng the latest ones, so I send it again. If you find it somewhere else as well, I apologize for that.

I use the following code to create a subset when the value of a variable is equal to a variable in another dataset.

proc sql;

create table want as select *

from have1 

where id in(select id from have2); quit;

However, I don't want to create a subset, but I want to say id_dummy=1 if id is in have2.

I appreciate any suggestion.

3 REPLIES 3
Reeza
Super User

If you don't have duplicates you can use a merge and check for matches.

 

If you have duplicates you can remove them and then use a merge and check for matches.

 

You could use an inline query with a CASE statement

 

CASE WHEN (SELECT A.NAME FROM HAVE AS _X WHERE A.NAME=_X.NAME) IS NOT NULL THEN 1
ELSE 0

 

stat_sas
Ammonite | Level 13

Try something like this:

 

data a;
input id;
datalines;
1
2
3
4
5
;

data b;
input id;
datalines;
2
3
;

proc sql;
select aa.*,case when aa.id=bb.id then 1 else 0 end as id_dummy from a aa left join b bb
on aa.id=bb.id;
quit;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1446 views
  • 0 likes
  • 3 in conversation