BookmarkSubscribeRSS Feed
Ranjeeta
Pyrite | Level 9
PROC CONTENTS of the COMBINEDSORTED DATASET:
Alphabetic List of Variables and Attributes# Variable Type Len Format Informat4521367
ADM_DTNum8DATETIME20.DATETIME20.
ADM_TMNum8DATETIME20.DATETIME20.
CIHI_KEYChar18 $16.
HCNEChar10 $10.
INST_NOChar4 $4.
REG_DTNum8DATETIME20.ANYDTDTM40.
REG_TMNum8DATETIME20.ANYDTDTM40

 

I am not sure why the temp is returning blank values

I am basically trying to delete any duplicate records that exist for HCNE by keeping the record with the earlier REG_TM or ADM_TM

I am not sure if the formatting is cusing the issue 

Please advise how to correct the same 

Regards

 

 



data two(keep=HCNE REG_TM ADM_TM temp); set Combinedsorted end=finished; by HCNE; retain temp; if not finished then do; pt = _N_ + 1; set Combinedsorted(rename= (HCNE=next_id REG_TM=next_regtm ADM_TM=next_admtm)) point=pt; if first.HCNE then do; if REG_TM < ADM_TM then temp=REG_TM; else temp=ADM_TM; if next_regtm < temp then temp=next_regtm; else if next_admtm < temp then temp=next_admtm; end; end; run; data final; set two; if REG_TM=temp or ADM_TM=temp then output; run; proc print; format REG_TM ADM_TM temp DATETIME20.; run;

 

2 REPLIES 2
hashman
Ammonite | Level 13

@Ranjeeta: Please show a small sample of your input data and the corresponding sample of output data you want to generate. A picture of data is worth a thousand words about the data.

 

Kind regards

Paul D.

ChrisNZ
Tourmaline | Level 20

Something like this?  (untested as you don't supply a data step with test data)


data WANT;
  merge COMBINEDSORTED
        COMBINEDSORTED(firstobs=2 rename=(HCNE=NEXT_ID  REG_TM=NEXT_REGTM ADM_TM=NEXT_ADMTM)) ;
  if HCNE=NEXT_ID ;
  MIN=min(REG_TM, NEXT_REGTM, ADM_TM, NEXT_ADMTM );
  if MIN=NEXT_REGTM | MIN=NEXT_ADMTM then do;
    REG_TM=NEXT_REGTM;
    ADM_TM=NEXT_ADMTM;
  end; 
run;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

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