Hi i have two tables with same variable name which contains yes or no as values and sequence number i want to create a new variable by comparing that value in both the tables like if the first table has no as an answer then i want to get yes from table 2.
table 1
| sequence number | findings |
| 1 | yes |
| 2 | yes |
| 3 | No |
| 4 | No |
| 5 | yes |
| 6 | No |
table 2
| sequence number | findings |
| 1 | no |
| 2 | no |
| 3 | yes |
| 4 | yes |
| 5 | yes |
| 6 | yes |
the output i want is this way
| sequence number | findings |
| 1 | yes |
| 2 | yes |
| 3 | yes |
| 4 | yes |
| 5 | yes |
| 6 | yes |
thanks in advance
data table1;
input sequence_number findings $;
cards;
1 yes
2 yes
3 No
4 No
5 yes
6 No
;
data table2;
input sequence_number findings $;
cards;
1 no
2 no
3 yes
4 yes
5 yes
6 No
;
data want;
merge table1 table2(rename=(findings=f));
if findings='No' and f='yes' then findings='yes';
drop f;
run;
data want;
merge table1 table2(rename=(findings=f));
if findings='No' and f='yes' then findings='yes';
drop f;
run;
NOTE; Your sequence 6 has NO in both tables, so that can't be YES in output
data table1;
input sequence_number findings $;
cards;
1 yes
2 yes
3 No
4 No
5 yes
6 No
;
data table2;
input sequence_number findings $;
cards;
1 no
2 no
3 yes
4 yes
5 yes
6 No
;
data want;
merge table1 table2(rename=(findings=f));
if findings='No' and f='yes' then findings='yes';
drop f;
run;
data want;
merge table1 table2(rename=(findings=f));
if findings='No' and f='yes' then findings='yes';
drop f;
run;
NOTE; Your sequence 6 has NO in both tables, so that can't be YES in output
thank you so much
what sets sequence number 6 to yes since both incoming tables has sequence number 6 as No?
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.