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

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
1yes 
2yes 
3No 
4No 
5yes 
6No 

 

table 2 

 

sequence number findings
1no 
2no 
3yes 
4yes 
5yes 
6yes

 

the  output i want is this way 

sequence number findings
1yes 
2yes 
3yes 
4yes 
5yes 
6yes

thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20




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

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20




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

Aayushi_17
Quartz | Level 8

thank you so much 

 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

what sets sequence number 6 to yes since both incoming tables has sequence number 6 as No?

 

Aayushi_17
Quartz | Level 8
sorry that table 1 should contain no and table 2 should contain yes

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 701 views
  • 0 likes
  • 3 in conversation