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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 5 replies
  • 1178 views
  • 0 likes
  • 3 in conversation