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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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