Hi ,
The above report I have created here i need a help how to create a new variable called totalpln which will be sum of "pln" for each month. Similarly other two variable as well.. . I have attached my SAS code.
Can someone help me
DATA planacthours;
INPUT prid $ taskname $ resourcename $9. month :monyy5. pln act var;
format month monyy5.;
CARDS;
pr15614 task1 resource1 Jan-21 20.0 10.0 10.0
pr15614 task1 resource1 Feb-21 20.0 20.0 0.0
pr15614 task1 resource1 Mar-21 20.0 30.0 -10.0
pr15614 task2 resource1 Apr-21 40.0 10.0 30.0
pr15614 task1 resource2 Jan-21 60.0 70.0 -10.0
pr15614 task2 resource2 Feb-21 60.0 40.0 20.0
pr15614 task1 resource2 Mar-21 20.0 10.0 10.0
pr15614 task2 resource2 Apr-21 80.0 10.0 70.0
pr15614 task1 resource3 Jan-21 20.0 10.0 10.0
pr15614 task1 resource3 Feb-21 40.0 60.0 -20.0
pr15614 task3 resource3 Mar-21 20.0 10.0 10.0
pr15614 task3 resource4 Jan-21 20.0 10.0 10.0
pr15614 task4 resource4 Apr-21 20.0 50.0 -40.0
pr15614 task4 resource4 Feb-21 20.0 10.0 10.0
;
RUN;
PROC REPORT DATA=test NOWD ;
COLUMN prid taskname resourcename month,(pln act var);
DEFINE prid / group;
DEFINE taskname / group;
DEFINE resourcename / group;
DEFINE month / across order=data;
DEFINE pln / analysis FORMAT=3.2;
DEFINE act / analysis FORMAT=3.2;
DEFINE var / analysis FORMAT=3.2;
/*DEFINE totalpln / display FORMAT=3.2;*/
/*define total/computed FORMAT=3.2;*/
/*compute total;*/
/*total=pln.sum;*/
/*endcomp;*/
RUN;
.
Hi:
Perhaps this is closer to what you envision:
PROC REPORT will allow you to put a variable on a report multiple times, as shown above. The first usage of PLN, ACT and VAR are in the COLUMN statement under the ACROSS variable. The next usage is to have them listed by themselves, for the final TOTAL columns at the far right.
However, in order to put in the Task Total and Grand Total labels at the breaks on the summary row, your sample program needed to have a LENGTH statement for PRID and RESOURCENAME so the field would be big enough for those total strings. "Task Total" is a length of 10 and "Grand Total" is a length of 11. Here's what the LENGTH statement looked like in the DATA step.
length prid $11 resourcename $10;
Otherwise the rest of the DATA step code was the same. I changed the dataset name to be TEST since that is what you used in the REPORT step.
Cynthia
Sum where? after each Task? after each Prid? Some other rule?
Yes, sum of each after each Task and after each Prid and each resourcename.
Your code is already summing at the Resourcename. Are you sure that it makes sense to sum again AFTER the resourcename?
I am looking for the above screenshot as an example. I was trying to get resolve the value for totalpln should be 60 for resource1. Similarly for totalact should be 60 for resource1..
Hi:
Perhaps this is closer to what you envision:
PROC REPORT will allow you to put a variable on a report multiple times, as shown above. The first usage of PLN, ACT and VAR are in the COLUMN statement under the ACROSS variable. The next usage is to have them listed by themselves, for the final TOTAL columns at the far right.
However, in order to put in the Task Total and Grand Total labels at the breaks on the summary row, your sample program needed to have a LENGTH statement for PRID and RESOURCENAME so the field would be big enough for those total strings. "Task Total" is a length of 10 and "Grand Total" is a length of 11. Here's what the LENGTH statement looked like in the DATA step.
length prid $11 resourcename $10;
Otherwise the rest of the DATA step code was the same. I changed the dataset name to be TEST since that is what you used in the REPORT step.
Cynthia
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.