Help using Base SAS procedures

grouping issue

Reply
Regular Contributor
Posts: 240

grouping issue

i have a data step that  groups by site I need to group by date as well. Currently it looks like this 

 

site id.       Machine                            Machine                                                     Machine

123.       04nov2015 09:39:12         04nov2015p 09:39:12                            23nov2015 09:39:12

 

i need to only see 11/04/15  one day than on its own row

siteid.  Machine

123.      23nov2015 09:39:12

 

my code is 

data report6 (drop=I n Mac  st et  dh) ;

retain siteid total machine1 starttime1 endtime1 dur_time1 &allvar. n;

format &mac. $10 &st . &et. Date time.;

set want3(rename =(machine2=Mac starttime2=st endtime2=et durtime2=dh();

by site_id machine1;

 

Array m(*) &Mac.;

array s(*) &st.;

Array e(*)&et.;

array d(*)&dh.;

if first .site Id  Or first.machine then 

do ; n=0;

do i=1 to &mx;

m(I) ="";s(I)=.;e(I)=.;d(I)=.;

end;

 

n+1;

m(n)=Mac;

s(n)=st;

e(n)=et;

d(n)=dh;

if last.siteid or last.machine1 then output report6;

run;

 

thanks for the assistance 

Super User
Posts: 19,770

Re: grouping issue

It looks like a wide to long transpose, there are two common ways - one is with an array and the second is with a transpose. 

 

If you're looking for the latest date you could use the max function to find the maximum date. 

 

Here are two write ups on how to transpose your data.

 

http://www.ats.ucla.edu/stat/sas/modules/wtol_transpose.htm

http://www.ats.ucla.edu/stat/sas/modules/widetolong_data.htm

Regular Contributor
Posts: 240

Re: grouping issue

I might have gotten it I did a datepart and added date  I then group it by site id. Machine. Date.  

Ask a Question
Discussion stats
  • 2 replies
  • 264 views
  • 0 likes
  • 2 in conversation