Help using Base SAS procedures

column percentage

Reply
N/A
Posts: 0

column percentage

?

I have used the following code to produce a table and I want the right hand column to calculate the percentage of the column based on the sum of var1, not the n value. At the moment each row has a value of 25%. Is there an easy way to do this?

data test;
input char1 $ char2 $ var1;
cards;
A A 10
A B 15
B A 20
B B 05
;
run;

proc tabulate data=test;
class char1 char2;
var var1;
table char1*char2 all,(var1 colpctn);
run;
N/A
Posts: 0

Re: column percentage

Posted in reply to deleted_user
I've replaced the tabulate with a freq, which gives me the percentages, but the ods output isn't working to get these values in a table so that I can work with them??

data test;
input char1 $ char2 $ var1;
cards;
A A 10
A B 15
B A 20
B B 05
;
run;


data test2;
set test;
char3=compress(char1||char2);
run;

proc freq data=test2;
tables char3 ;
weight var1;
ods output table=test3;
run;
SAS Super FREQ
Posts: 8,862

Re: column percentage

Posted in reply to deleted_user
Hi:
Also, the syntax for creating an output data set from Proc Freq is wrong. To create an output dataset use one of these 2 methods (not both):
1) use Proc FREQ syntax
2) use ODS syntax.

If you use ODS syntax, then the ODS output statement must PRECEDE the Proc Freq -and- you must have the right output object <object> for the procedure:
[pre]
ods trace on / label;
ods output <object> = dataset;
proc freq data=mydata;
table char3;
run;
ods trace off;
[/pre]

The documentation can show you the right syntax for the PROC FREQ method and the ODS TRACE and the ODS documentation can show you the correct syntax for the ODS method. The ODS TRACE will give you the name of the correct output object. As far as I know, "TABLE=TEST3" should fail because "TABLE" is not the correct output object name created by PROC FREQ.

cynthia
N/A
Posts: 0

Re: column percentage

Posted in reply to deleted_user
have you tried COLPCTSUM instead of COLPCTN

PeterC
N/A
Posts: 0

Re: column percentage

Posted in reply to deleted_user
Brilliant Peter thanks.
Ask a Question
Discussion stats
  • 4 replies
  • 136 views
  • 0 likes
  • 2 in conversation