BookmarkSubscribeRSS Feed
deleted_user
Not applicable
?

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;
4 REPLIES 4
deleted_user
Not applicable
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;
Cynthia_sas
SAS Super FREQ
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
deleted_user
Not applicable
have you tried COLPCTSUM instead of COLPCTN

PeterC
deleted_user
Not applicable
Brilliant Peter thanks.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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