Help using Base SAS procedures

Merge?

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,041
Accepted Solution

Merge?

I have duplicates by mrn

i want no duplicates by mrn as shown below and wanted everything to be fitted in a single row

Is that possible?????

Thanks

Hi I have
mrn    in1           out1         in2          out2        in3         out3

101    time1                       time3                    time5

101                    time2                     time4                    time6

I want

mrn    in1           out1         in2          out2        in3         out3

101    time1         time2     time3         time4   time5     time6


Accepted Solutions
Solution
‎05-01-2013 11:48 AM
Super User
Posts: 5,513

Re: Merge?

Posted in reply to robertrao

An easy way:

data want;

   update have (obs=0) have;

   by mrn;

run;

But if you're going to want to understand the tools and how they work, you are better off studying Reeza's link.  Those tools are more important than this program.  Good luck.

Ooops ... Looks like I'm a little slow on the draw today!

View solution in original post


All Replies
Super User
Posts: 19,832

Re: Merge?

Posted in reply to robertrao

Yes it is possible, look up retain and lag.

http://changchung.com/download/retainLagLeadInterleave_draft.pdf

Solution
‎05-01-2013 11:48 AM
Super User
Posts: 5,513

Re: Merge?

Posted in reply to robertrao

An easy way:

data want;

   update have (obs=0) have;

   by mrn;

run;

But if you're going to want to understand the tools and how they work, you are better off studying Reeza's link.  Those tools are more important than this program.  Good luck.

Ooops ... Looks like I'm a little slow on the draw today!

Respected Advisor
Posts: 3,156

Re: Merge?

Posted in reply to Astounding

"Ooops ... Looks like I'm a little slow on the draw today!"

Not anymore. Your post has more information, deserves "shoot and kill". Smiley Happy

Haikuo

Super Contributor
Posts: 1,041

Re: Merge?

Posted in reply to Astounding

Thanks so much for the help..

Why is the obs=0 used

and why only for one of the two have datasets????

Regards

Super User
Posts: 5,513

Re: Merge?

Posted in reply to robertrao

If you're confident that you understand how the UPDATE statement works, I can answer that.  But if not, you are better off studying other tools such as Reeza's link.

Super Contributor
Posts: 1,041

Re: Merge?

Posted in reply to Astounding

Yes I do..

It updates the dataset with the by variable...

so if there is missing out1 in the first dataset (101) and i the second dataset (101) has a value then

it updates the inforamtion

Super User
Posts: 5,513

Re: Merge?

Posted in reply to robertrao

OK, so the first data set is the master list and cannot have any duplicated MRNs.  The second data set can have multiple observations per MRN.  Any MRN in the second data but not in the first automatically gets added to the final data set.

The UPDATE statement requires both data set names (master first, transaction second). So obs=0 just creates an empty master data set, but with exactly the same variable definitions as in the transaction data set.  The name of a master data set is required by UPDATE, but it doesn't have to actually hold any data.  All the data will come from the transaction data set.

Super Contributor
Posts: 1,041

Re: Merge?

Posted in reply to Astounding

Thanks so much..

Reezas notes was helpful too..But I did not know which part of that notes is useful..

Great Help

Super User
Posts: 10,041

Re: Merge?

Posted in reply to Astounding

Actually I am always late due to in another time zone.

To OP, If you cann't understand what UPDATE is doing, and your variables are all numeric. Here is a more explicit way you might see .

proc means data=have;

by mrn;

var in: out: ;

output out=want sum= ;

run;

Ksharp

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 367 views
  • 3 likes
  • 5 in conversation