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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

9 REPLIES 9
Reeza
Super User

Yes it is possible, look up retain and lag.

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

Astounding
PROC Star

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!

Haikuo
Onyx | Level 15

"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

robertrao
Quartz | Level 8

Thanks so much for the help..

Why is the obs=0 used

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

Regards

Astounding
PROC Star

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.

robertrao
Quartz | Level 8

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

Astounding
PROC Star

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.

robertrao
Quartz | Level 8

Thanks so much..

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

Great Help

Ksharp
Super User

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

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