Help using Base SAS procedures

removing dups in cell

Reply
Regular Contributor
Posts: 240

removing dups in cell

Hi I have a rows of data an wanted to remove any dups the data looks like this

Machine. start 1.
A1. 11/01/15 12:34:00.
Start2
11/01/15 09:34:00
Start3.
11/01/15 09:34:00
I don't have room I didn't inlude the end time which would be also duplex ....thanks

Super User
Posts: 5,503

Re: removing dups in cell

First step would be to read the data into a SAS data set.  Once you have done that, show us what it looks like and we'll find a way to get rid of those pesky dups.

Regular Contributor
Posts: 240

Re: removing dups in cell

Posted in reply to Astounding

It looks some thing like this

 

machine1.       Start1.                  end1.                Machine2.             Start2.         end2.              Machine3.    Start3.                  End3

A1.            11/01/15 11:21.      11/01/15 11:38.       A1.           11/01/15 11:30 11/01/15 11:35.        A1       11/01/15 11:21. 11/01/15 11:38

 

sometimes there are up to 5 machines but normally there are 3 what I need is to remove the duplicates and keep one of the two....

 

Thanks

Super User
Posts: 10,023

Re: removing dups in cell

data want;

 set have;

 array m{*} machine: ;

 array s{*} Start: ;

 array e{*} end: ;

do i=1 to dim(m);

 ma=m{i};

 st=s{i};

 en=e{i};

output;

end;

drop machine: Start: end:  ;

run;

 

proc sort data=want nodupkey ; by ma st en; run;

Regular Contributor
Posts: 240

Re: removing dups in cell

Ksharp

I ran syntax it drop my start 2 end 2 Start3 End3

It put columns I ma. St. En. ..I need the output to look like my examples minus the duplicate...the time in St an en is formated 1762078330 .... thanks for your help
Super User
Posts: 10,023

Re: removing dups in cell

data have;
input machine1 $ ( Start1   end1) (& anydtdtm.) Machine2 $  (Start2    end2) (& anydtdtm.) Machine3 $   (Start3  End3) (& anydtdtm.);
format _numeric_ datetime.;
cards;                 
A1  11/01/15 11:21  11/01/15 11:38  A1  11/01/15 11:30   11/01/15 11:35   A1   11/01/15 11:21  11/01/15 11:38
A1  11/01/15 11:21  11/01/15 11:38  A1  11/01/15 11:30   11/01/15 11:35   A2   11/01/15 11:21  11/01/15 11:38
;
run;

data want;
if _n_ eq  1 then do;
 length _machine $ 100 _Start _end 8;
 declare hash h();
 declare hiter hi('h');
 h.definekey('_machine','_Start','_end');
 h.definedata('_machine','_Start','_end');
 h.definedone();
end;
 set have;
 array m{*} machine: ;
 array s{*} Start: ;
 array e{*} end: ;
do i=1 to dim(m);
 _machine=m{i};_Start=s{i};_end=e{i};
 h.replace();
end;
call missing(of m{*} s{*} e{*});
i=0;
do while(hi.next()=0);
 i+1;
 m{i}=_machine;s{i}=_Start;e{i}=_end;
end;
h.clear();
drop _: i ;
run;
Ask a Question
Discussion stats
  • 5 replies
  • 381 views
  • 0 likes
  • 3 in conversation