BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SahooP
Fluorite | Level 6

proc report.PNG

 

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;

.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
Diamond | Level 26

Hi:

  Perhaps this is closer to what you envision:

Cynthia_sas_0-1615393132900.png

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

View solution in original post

7 REPLIES 7
ballardw
Super User

Sum where? after each Task? after each Prid? Some other rule?

SahooP
Fluorite | Level 6

Yes, sum of each after each Task and  after each Prid and each resourcename.

ballardw
Super User

Your code is already summing at the Resourcename. Are you sure that it makes sense to sum again AFTER the resourcename?

SahooP
Fluorite | Level 6
Yes, I have create three different additional column for pl, act and var . That should be sum of each month. For example as per given screenshot the first row sum pln should be should be 60 for resource1 that column should be totalpln.
SahooP
Fluorite | Level 6

PR1.PNG

 

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

Cynthia_sas
Diamond | Level 26

Hi:

  Perhaps this is closer to what you envision:

Cynthia_sas_0-1615393132900.png

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

SahooP
Fluorite | Level 6
Thank you so much for your help.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1603 views
  • 1 like
  • 3 in conversation