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

Hello guys,

 

I have two datasets A  and B. A is a baseline dataset and B is the death dataset. 

 

I want to merge using the "In= " to select only Ids that are in dataset A.

 

Then also in the merge i want to create a flag using "in=" to determine that the patient died. 

 

My code is attached.

 

Any help will be appreciated.

data forty;
merge sleep2(in=x) three (in=y);
if in=x then died=y;
run;
proc print; run;
1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Some code like below should do.

data want;
  merge A(in=ina) B (in=inb);
  by id;
  /* only select rows with an ID in table A */
  if ina;
  /* set died_flg='Y' if a matching ID in table B */
  if inb then
    died_flg='Y';
  else died_flg='N';
run;

proc print;
run;

View solution in original post

3 REPLIES 3
ChuksManuel
Pyrite | Level 9

data forty;
merge sleep2(in=x) three (in=y);

by id;
if in=x then died=y;
run;
proc print; run;

Patrick
Opal | Level 21

Some code like below should do.

data want;
  merge A(in=ina) B (in=inb);
  by id;
  /* only select rows with an ID in table A */
  if ina;
  /* set died_flg='Y' if a matching ID in table B */
  if inb then
    died_flg='Y';
  else died_flg='N';
run;

proc print;
run;

AI Navigator GIF.gif


Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.

Check it out on Microsoft Marketplace →

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1894 views
  • 0 likes
  • 2 in conversation