Trying the replicate the method in this example
https://support.sas.com/kb/49/390.html
but I get an error on the compute blocks
27 proc report data=table10_1;
28 col Var_name Var_Value CY, (cnt cntpct);
29 define Var_name / Group '' ;
30 define Var_Value / Group '';
31 define CY / across '';
32 define cnt / sum '#' format=comma8.;
33 define cntpct / computed '%' format=percent7.1;
34 compute before Var_value;
35 cnttot=cnt.sum;
36 endcomp;
37 compute cntpct;
38 if cnttot gt 0 then cntpct=cnt.sum / cnttot;
39 endcomp;
40 run;
ERROR: The variable type of 'CNT.SUM'n is invalid in this context.
NOTE: The preceding messages refer to the COMPUTE block for cntpct.
ERROR: The variable type of 'CNT.SUM'n is invalid in this context.
NOTE: The preceding messages refer to the COMPUTE block for BREAK BEFORE Var_value.
NOTE: Will not run due to compilation errors.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 130475 observations read from the data set WORK.TABLE10_1.
NOTE: PROCEDURE REPORT used (Total process time):
real time 0.02 seconds
cpu time 0.09 seconds
Hi: Without some sample data, nobody can run your code. I have a few thoughts about what you're trying to do. CNT and CNTPCT are both nested UNDER an ACROSS item, CY. That is the major difference between the code in the Tech Support note and the code you posted.
More thoughts: you can't use the "simple" name in your COMPUTE block. You have to use the absolute column number that is calculated by PROC REPORT behind the scenes. Take a look at this paper https://support.sas.com/resources/papers/proceedings14/SAS388-2014.pdf -- in particular, the example on pages 8, 9 and 10 so that you can see a concrete example of how absolute column numbers are created by PROC REPORT with ACROSS items. The other challenge is the way you are creating CNTTOT. Your only placement of CNT is UNDER an ACROSS item, so calculating the percent using the reference to CNT.SUM is not going to work. In the SAME paper, on pages 10,11 you can see how a percent is calculated for every item under an ACROSS item.
Cynthia
Hi: Without some sample data, nobody can run your code. I have a few thoughts about what you're trying to do. CNT and CNTPCT are both nested UNDER an ACROSS item, CY. That is the major difference between the code in the Tech Support note and the code you posted.
More thoughts: you can't use the "simple" name in your COMPUTE block. You have to use the absolute column number that is calculated by PROC REPORT behind the scenes. Take a look at this paper https://support.sas.com/resources/papers/proceedings14/SAS388-2014.pdf -- in particular, the example on pages 8, 9 and 10 so that you can see a concrete example of how absolute column numbers are created by PROC REPORT with ACROSS items. The other challenge is the way you are creating CNTTOT. Your only placement of CNT is UNDER an ACROSS item, so calculating the percent using the reference to CNT.SUM is not going to work. In the SAME paper, on pages 10,11 you can see how a percent is calculated for every item under an ACROSS item.
Cynthia
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.