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;
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
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
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.