BookmarkSubscribeRSS Feed
LAtwood
Calcite | Level 5


I have the following example of data:

Clock Num     Date          In          Out          Turn      Hrs     Turn     Paycode               Amount    DAILY **Column I want to add

69900            3/3/14       7:34       17:33         

69900            3/3/14                                     2          9.5

69900            3/3/14                                                            2      CREWLEADER          1

69900            3/3/14                                                            2      PROD HRS                8

69900            3/3/14                                                            3      CREWLEADER          1

69900            3/3/14                                                            3      PROD HRS               1.5          9.5

The column titled Hrs; I want to SUM and display on the last line of data by Clock Num and Date.  Daily = sum(Hrs)

I have the following code and I am using proc report compute.  I am unsure how to display the total on the last line of data.

proc report data = test nowd;

column clock_num turn_dt in_tm out_tm hrs_turn_ident hrs_dec turn_ident pay_cd amt_dec daily;

define clock_num / group 'Clock Num';

define turn_dt / group 'Date' ;

define in_tm / display 'In';

define out_tm / display 'Out';

define hrs_turn_ident / display 'Turn';

define hrs_dec / display 'Hrs';

define turn_ident / display 'Turn';

define pay_cd / display 'Paycode';

define amt_dec / display 'Amount';

define daily / computed 'Daily';

define turn_dt / order;

break after turn_dt / ;

compute daily;

daily=sum(hrs_dec);

endcomp;

run;

2 REPLIES 2
Cynthia_sas
SAS Super FREQ

Hi:
It is not entirely clear to me why you want the total hours to appear on the last row of data. It is very hard to detect the last data row. You could get PROC REPORT to compute the value for you if you used a BREAK statement, but you'd have to change the usage of hrs_dec to SUM instead of DISPLAY. And the total of hrs_dec would appear in that column on a separate row.

cynthia

Ksharp
Super User

Why not do it in data step ?

data have;
input num date : mmddyy10. hrs ;
format date mmddyy10.;
cards;
1 3/3/14 .
1 3/3/14 9.5 
1 3/3/14 .
1 3/3/14 .
2 3/4/14 7.9
2 3/4/14 .
2 3/5/14 .
2 3/5/14 .
;
run;
data have;
 set have;
 by num date;
 s+hrs;
 if last.date then do;daily=s; s=.;end;
 drop s;
run;


Xia Keshan

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!

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
  • 898 views
  • 0 likes
  • 3 in conversation