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!
Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.
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.
Ready to level-up your skills? Choose your own adventure.