BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Batman
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

View solution in original post

1 REPLY 1
Cynthia_sas
SAS Super FREQ

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

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 147 views
  • 0 likes
  • 2 in conversation