Hi Team,
For a particular patient there might be many procedures done.But I want to eliminate the duplicates of the same procedure if any.......
patient proc_code
101 CPT
101 CPT
101 CPT
101 SPT
101 OMT
I want:
patient proc_code
101 CPT
101 SPT
101 OMT
Regards
one way:
data have;
input patient proc_code $;
cards;
101 CPT
101 CPT
101 CPT
101 SPT
101 OMT
;
proc sort data=have out=want nodupkey;
by patient proc_code;
run;
proc print;run;
one way:
data have;
input patient proc_code $;
cards;
101 CPT
101 CPT
101 CPT
101 SPT
101 OMT
;
proc sort data=have out=want nodupkey;
by patient proc_code;
run;
proc print;run;
Hi,
Thanks so much...is there any way i can use this with out the nodupkey??
maybe retain
Regards
I don't think you can do it by retain.
another way:
data want;
set have;
by patient proc_code notsorted;
if last.proc_code;
proc print;run;
Hi,
What is notsorted?is it an option?
Whats the use of it?could you please explain
Regards
Notsorted means just that: the data is not sorted. But you want first. and last. automatic variables to reflect every change in the sequence anyway, as if it was sorted. - PG
Hi,
This code still has duplicates of patient and proc_code.Do not know the reason.but they are intermingled with other data.
I think it is good for me to follow the nodupkey
Regards
-----yet another way:
data have;
input patient proc_code $;
cards;
101 CPT
101 CPT
101 CPT
101 SPT
101 OMT
;
run;
data _null_;
if(1=2)then set have;
declare hash prc(dataset:"have",ordered:"a");
rc=prc.defineKey("patient","proc_code");
rc=prc.defineDone();
rc=prc.output(dataset:"want");
run;
Joe, I have to ask, Is there a particular reason you choose to use 'if (1=2)' instead of 'if 0', since (1=2) would always be 0? Haikuo
Aha, Hai.Kuo the observant one!
IF(0) versus IF(1=2): I'm still brainstorming for suitable answers:
(1) "Different strokes for different folks (like CARDS vs DATALINES)".
(2) "Less mystifying to FORTRAN programmers".
(3) "Better understood by SAS debutantes".
(4) "Personal signature. (if you see that on planet Mars, then you know I'm there)"
(5) "Just being a little mischievous, getting the processor to spend an extra nanosecond".
(6) "More palatable to the human Visual and Prefrontal cortices".
(7) "More mathematically appropriate".
(8) ?
(9) ?
- -
COULD THERE BE A CATCH?
See the link below:
http://www.math.toronto.edu/mathnet/falseProofs/first1eq2.html
I like your answer, you made my day, Joe.:smileylaugh:
Haikuo
select distinct * from have ;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.