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

Hello,

 

I am trying to work out how to get a percentage within my proc tabulate for the sum of a variable within column, without having a column variable. I have tired the below code. Though this only produces the col % for the total population. Does any body know how to get it to produce the % for the Value.

 

proc tabulate data=book;
title 'Age band';
table Pet_Type ="Pet'', (n pctn Value colpctn<Value>);
class Pet_type /missing;
var Value;
run;

 

What this gives me is:

Total number falling within each band (N)

% for the t 

total summed up value associated to the Pets 

% for the col for total again.

 

I have shown two tables with the current vs what i wish to produce. 

Current output 

Pet            N    PctN   Value    ColPctN Value
a. Dog      80   30.65   15000   30.65
b. Cat       74   28.35   10000   28.35
c. Rodent 42   16.09   5000     16.09
d. Fish      55   21.07  8000      21.07
e. Other    10   3.83   1000       3.83

 

Expected Output

 

Pet            N    PctN   Value    ColPctN Val
a. Dog      80   30.65   15000   38.46
b. Cat       74   28.35   10000   25.64
c. Rodent 42   16.09   5000     12.82
d. Fish      55   21.07  8000      20.51
e. Other    10   3.83   1000       2.56

 

Is the expected output possible within an proc tabulate without a column header?

 

Thank you,

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:
Without your WORK.BOOK data, no one can run your code. Can you either post your data, post some test data, or rework your example using one of the SASHELP datasets? I think from what you describe that you need to switch to the PCTSUM statistic in the table. But I'm not entirely sure. Here's an example using N and PCTN and then SUM and PCTSUM for a numeric variable:

Cynthia_sas_0-1612285343114.png

Cynthia

View solution in original post

3 REPLIES 3
Cynthia_sas
SAS Super FREQ

Hi:
Without your WORK.BOOK data, no one can run your code. Can you either post your data, post some test data, or rework your example using one of the SASHELP datasets? I think from what you describe that you need to switch to the PCTSUM statistic in the table. But I'm not entirely sure. Here's an example using N and PCTN and then SUM and PCTSUM for a numeric variable:

Cynthia_sas_0-1612285343114.png

Cynthia

Mick_bill
Fluorite | Level 6

thank you, this is perfect. 

ballardw
Super User

Without your starting data set there really isn't any way to see if what you want is practical in Proc Tabulate.

Proc tabulate to use a variable in a Pctn<var> will require the variable to be in the table somewhere, and pretty picky about where it can be.

 

Are you sure that you don't want colpctsum of Value?

proc tabulate data=book;
title 'Age band';
table Pet_Type ="Pet'', 
n pctn Value*sum=' '  value=' '*colpctsum=' ';
class Pet_type /missing;
var Value;
run;

You can use the variablename=' ' or statistic*' ' to provide a blank label

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 595 views
  • 0 likes
  • 3 in conversation