BookmarkSubscribeRSS Feed
alwaz_searching
Calcite | Level 5
I want to create same output with these datalines by merge statment and Proc Sql ....

While doing mergeing I get the note: The Merge statement has one dataset with repeats of By variable...with correct output and in Proc Sql it gives me cartesian product...

is there any alternate way apart from these two..??? Please guide on this ..

data abc;
input pt subj $ trt $;

datalines;
1 111-22 trt
1 111-22 wew
1 111-33 fgd
2 111-22 bdb
2 111-22 fgd
2 111-33 dfg
2 111-33 fsa
2 111-33 bvb
;
run;

data xyz;
input pt subj $ vis ;

datalines;
1 111-22 2
1 111-22 3
1 111-33 2
2 111-22 1
2 111-22 1
2 111-33 2
2 111-33 7
;
run;

proc sort data=abc nodup ;
by pt subj;
run;

proc sort data=xyz nodup;
by pt subj;
run;

data lmn;
merge abc(in=a) xyz(in=b);
by pt subj ;
if a and b;
run;

**********************************Alternate method***********************************;
proc sql;
select distinct abc.*,vis from abc inner join xyz

on abc.pt=xyz.pt and abc.subj=xyz.subj group by abc.pt , abc.subj;
quit;
5 REPLIES 5
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Alwaz,

It is not completely clear to me what would you like to achieve. If you write NODUPKEY instead of NODUP then duplicate by groups will be eliminated from ABC and XYZ and merge will not generate any warnings. Is it your intention?

Sincerely,
SPR
alwaz_searching
Calcite | Level 5
Ya, that's right but it 'll remove the third variable's values also....
Ksharp
Super User
What ouput do you want to look like?


Ksharp
alwaz_searching
Calcite | Level 5
Below is the desired output but it comes with the usual note of the merge statement of repeats of by variable values in log.

How can I remove it?

pt subj trt vis

1 111-22 trt 2
1 111-22 wew 3
1 111-33 fgd 2
2 111-22 bdb 1
2 111-22 fgd 1
2 111-33 dfg 2
2 111-33 fsa 7
2 111-33 bvb 7
Ksharp
Super User
Why do you want to remove this message, It is only NOTE message,not WARNING or ERROR message.
If you do not want to see these NOTE message,you can try to use " options nonotes; "


Ksharp

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1592 views
  • 0 likes
  • 3 in conversation