turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- How to correctly calculate the result by using PCT...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-08-2017 05:12 PM

In the below Proc Tabulate, I am dividing the numerator by denominator using pctsum. I want to show the result as 0.3077, 0.1579, 0.4667 and 0.1515 for A, B, C and D respectively, instead of the result shown in the below table. Is there any way to get the correct result? Thanks.

**DATA** TEST;

INPUT STORE$ NUM DENOM ;

CARDS;

A 4 13

B 3 19

C 7 15

D 5 33

;

**RUN**;

**PROC** **TABULATE** DATA=TEST;

CLASS STORE;

VAR NUM DENOM;

TABLE STORE, NUM="RESULT"*PCTSUM<DENOM> * FORMAT=**7.2**;

**RUN**;

| RESULT |

PctSum | |

STORE | 30.77 |

A | |

B | 15.79 |

C | 46.67 |

D | 15.15 |

Accepted Solutions

Solution

07-08-2017
08:39 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Shmuel

07-08-2017 07:56 PM

Hi:

Another option, in the interest of completeness, would be to use PROC REPORT. When you use PROC REPORT, it does NOT automatically multiply by 100 because you can control the division yourself, like this:

```
proc report data=test;
column store num denom result;
define store / display;
define num / sum;
define denom / sum;
define result / computed f=6.4;
compute result;
result = num.sum / denom.sum;
endcomp;
run;
```

And, then, if you don't want to see num or denom on the report, you can add the NOPRINT option to the DEFINE statement (after the usage of SUM).

The output looks like this:

cynthia

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-08-2017 07:21 PM

PCTSUM converts the result into PERCENT by multipying it by 100.

You can do:

```
DATA TEST;
INPUT STORE$ NUM DENOM ;
result = num/denom;
CARDS;
A 4 13
B 3 19
C 7 15
D 5 33
;
RUN;
PROC TABULATE DATA=TEST;
CLASS STORE;
VAR NUM DENOM;
TABLE STORE, RESULT* FORMAT=7.2;
RUN;
```

Solution

07-08-2017
08:39 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Shmuel

07-08-2017 07:56 PM

Hi:

Another option, in the interest of completeness, would be to use PROC REPORT. When you use PROC REPORT, it does NOT automatically multiply by 100 because you can control the division yourself, like this:

```
proc report data=test;
column store num denom result;
define store / display;
define num / sum;
define denom / sum;
define result / computed f=6.4;
compute result;
result = num.sum / denom.sum;
endcomp;
run;
```

And, then, if you don't want to see num or denom on the report, you can add the NOPRINT option to the DEFINE statement (after the usage of SUM).

The output looks like this:

cynthia

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-08-2017 08:43 PM

Hi Cynthia, thanks for the alternative solutions! I wonder if I can do the following:

Var result / weight = .01;

I assume it may work fine with either 0.01 in numerator weight or 100 in denominator weight. Below is what I found from the sas website, can you give me some advices? Thanks a lot!

Weight the Results II

You can also use the WEIGHT= option to apply weights specifically to individual variables. You do this by applying weights to individual variables with multiple VAR statements.

This means that you can produce tables where different weights are used for different variables, or one variable is weighted and another is not. Or, by making a copy of your analysis variable, you can show that variable both weighted and unweighted in the same table.

From the SAS site (via Dartmouth edu) - http://morgan.dartmouth.edu/Docs/sas92/support.sas.com/documentation/cdl/en/proc/61895/HTML/default/...

Var result / weight = .01;

I assume it may work fine with either 0.01 in numerator weight or 100 in denominator weight. Below is what I found from the sas website, can you give me some advices? Thanks a lot!

Weight the Results II

You can also use the WEIGHT= option to apply weights specifically to individual variables. You do this by applying weights to individual variables with multiple VAR statements.

This means that you can produce tables where different weights are used for different variables, or one variable is weighted and another is not. Or, by making a copy of your analysis variable, you can show that variable both weighted and unweighted in the same table.

From the SAS site (via Dartmouth edu) - http://morgan.dartmouth.edu/Docs/sas92/support.sas.com/documentation/cdl/en/proc/61895/HTML/default/...

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-09-2017 12:07 PM

Hi, Where do you want to use the WEIGHT= option? PROC REPORT does not use a VAR statement, so my assumption would be that you are using WEIGHT= with either PROC MEANS or TABULATE. TABULATE always multiplies by 100 in the calculation of statistics. I showed you a PROC REPORT solution. With PROC REPORT, there is no need to fiddle with the results.

If you want a TABULATE solution, they try out the VAR statement with TABULATE and see whether it works as you envision.

cynthia

If you want a TABULATE solution, they try out the VAR statement with TABULATE and see whether it works as you envision.

cynthia

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Cynthia_sas

07-10-2017 10:46 AM

**Hi Cynthia, I was trying to use the weight statment in the Proc Tabulate like below. I figured out that I have to add the "weight" in the orginal dataset which is test in my case and apply the weight in the Proc tabualte, then the result would be deflated by 100. Thanks for your helps! **

**DATA** TEST;

INPUT STORE$ NUM DENOM WEIGHT;

CARDS;

A 4 13 0.01

B 3 19 0.01

C 7 15 0.01

D 5 33 0.01

;

**RUN**;

**PROC** **TABULATE** DATA=TEST;

CLASS STORE;

VAR DENOM;

VAR NUM / WEIGHT=WEIGHT;

TABLE STORE, NUM="RESULT"*PCTSUM<DENOM> * FORMAT=**7.2**;

**RUN**;

| RESULT |

PctSum | |

STORE | |

A | 0.31 |

B | 0.16 |

C | 0.47 |

D | 0.15 |

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-10-2017 12:42 PM

Hi:

I'm glad you worked it out. Just note that with PROC REPORT you do NOT need to have a WEIGHT variable because PROC REPORT does NOT multiply by 100 in the first place.

cynthia

I'm glad you worked it out. Just note that with PROC REPORT you do NOT need to have a WEIGHT variable because PROC REPORT does NOT multiply by 100 in the first place.

cynthia