BookmarkSubscribeRSS Feed
RHL
Calcite | Level 5 RHL
Calcite | Level 5
Hi,

I'm trying to duplicate PROC TABULATE code in EG using the Summary Tables task but have a problem with calculating percentages. How would you create the equivalent of PCTN< > (calculating the percentage based on a class variable, not necessarily the whole row or column)?

Thanks in advance for any help.
4 REPLIES 4
Cynthia_sas
Diamond | Level 26
Hi:
I do not know whether there's a way to specify a custom denominator in the EG wizard or task. You may have to generate a simple N and PCTN table and then modify the generated code to use a custom denominator with the < and > angle brackets.

See the code example below. The custom denominator (in the second table definition) tells Proc Tabulate to calculate the PCTN across all the products within each region. So, you would see in this instance, that the PCTN for all the products for each region will add up to 100%.

cynthia
[pre]
ods html file='custom_denom.html' style=sasweb;

proc tabulate data=sashelp.shoes;
where region in ('Asia', 'Canada', 'Pacific');
title 'Compare These Tables';

class region product;

table region*(product all) all,
n pctn
/box='1) Regular N and PctN';

table region*(product all) all,
n pctn<product all>
/box='2) Custom Denominator';

run;

ods html close;
[/pre]
RHL
Calcite | Level 5 RHL
Calcite | Level 5
Hi Cynthia,

I've tried to do what you suggested, but I don't think EG allows me to insert code at the point where I need to put the angle brackets.
Cynthia_sas
Diamond | Level 26
Hi:
You may be right, that there's no way to insert the code in the EG task.

The thing you may have to do is to highlight the task in EG and then Export the code. Save the code file to a location where you can find it again. Then open the code file in a code node and edit the code.

At this point, you will need to test the code node to be sure that it produces the output you want. Once you know that you've edited the code and are getting the results you want, you probably don't want/need the original Summary Tables Task anymore and can use the code node instead to generate your report.

cynthia
RHL
Calcite | Level 5 RHL
Calcite | Level 5
I guess this means that it really can't be done just by point and click, or drag and drop. I could just as easily type the code into a code node.

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

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 4 replies
  • 2181 views
  • 0 likes
  • 2 in conversation