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;
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;
data forty;
merge sleep2(in=x) three (in=y);
by id;
if in=x then died=y;
run;
proc print; run;
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;
Thanks!
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.