Help using Base SAS procedures

Proc SQL and Merge

Reply
Occasional Contributor
Posts: 13

Proc SQL and Merge

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;
Super Contributor
Super Contributor
Posts: 365

Re: Proc SQL and Merge

Posted in reply to alwaz_searching
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
Occasional Contributor
Posts: 13

Re: Proc SQL and Merge

Ya, that's right but it 'll remove the third variable's values also....
Super User
Posts: 10,041

Re: Proc SQL and Merge

Posted in reply to alwaz_searching
What ouput do you want to look like?


Ksharp
Occasional Contributor
Posts: 13

Re: Proc SQL and Merge

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
Super User
Posts: 10,041

Re: Proc SQL and Merge

Posted in reply to alwaz_searching
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
Ask a Question
Discussion stats
  • 5 replies
  • 381 views
  • 0 likes
  • 3 in conversation