Help using Base SAS procedures

proc surveyfreq

Reply
Super Contributor
Posts: 338

proc surveyfreq

Hi Colleagues,

I have a data set like this.

data food;
input id sex status wt;
cards;
1 1 1 33
2 2 1 33
3 1 2 33
4 2 2 10
5 1 1 10
6 1 2 10
7 1 2 33
8 2 2 10
;
run;


/*Id = id*/
/*Sex = sex of respondent (1=male, 2= female)*/
/*Status = food security status (1=secure, 2=insecure)*/
/*Wt = weight variable*/

Using proc surveyfreq, I have generated the cross tabs for the
population.

proc surveyfreq data=food;
tables sex*status;
weight wt;
run;

Finally however my report has to present the frequency counts and associated percentages for the following combinations:
Sex 1 & Status 1
Sex 1 & Status 2
Sex 2 & Status 1
Sex 2 & Status 2

SAS output presents the frequency counts and associated percentages differently. So, I am manually calculating the percentages for the above combinations using the freq counts generated by SAS output.

Query: Would there be any optional statements in the proc surveyfreq that would straight a way generate the percentages of my interest.
Thank you for the inputs.

Neil
Frequent Contributor
Posts: 95

Re: proc surveyfreq

It seems to me that proc surveyfreq is producing what you need. This is the output I get when I use the code you provided (with a few options turned off). Am I misunderstanding your question?

[pre]
Table of sex by status

Weighted
sex status Frequency Percent
------------------------------------------------------
1 1 43.00000 25.0000
2 76.00000 44.1860
-----------------------------------------------------
2 1 33.00000 19.1860
2 20.00000 11.6279
------------------------------------------------------
[/pre]
Super Contributor
Posts: 338

Re: proc surveyfreq

Hi Colleague (1162),

Many thanks for this. Yes this is the output I also get.

But I need to get the percentages of each 'status' within a 'sex' group seperately.

For example,
Sex 1 and Status 1 =36.13% (but the output gives 25%)
Sex 1 and Status 2 = 63.86% (but the output gives 44%)
Sex 2 and Status 1 = 62.26% and so on.

I am extracting the output into an Excel sheet and manually calculating the needed % s but it takes time as I have 50 such output tables.

So, is there any optional statement in proc surveyfreq to calculate the desired %s within SAS itself.


One more thing, could you also please let me know how did you make it to appear your SAS output table in the psoted messege? I tried but tables are not accepted in messege box.
Thanks

Neil
Occasional Contributor P_J
Occasional Contributor
Posts: 10

Re: proc surveyfreq

Do you mean the results like below ?

sex=1 status=1 COUNT=43 PERCENT=36.134453782
sex=1 status=2 COUNT=76 PERCENT=63.865546218
sex=2 status=1 COUNT=33 PERCENT=62.264150943
sex=2 status=2 COUNT=20 PERCENT=37.735849057

Then please try by adding by sex;

proc freq data=food;
by sex ;
tables status /nocum out=food1;
weight wt;
run;
Super Contributor
Posts: 338

Re: proc surveyfreq

Hi P.J.

Of course yes. Those are exactly the percentages that I need for four combinations of sex and status. I am calculating these % s seperately in Excel (manualy) which takes ages.

However, following program does not generate it.

proc freq data=food;
by sex ;
tables status /nocum out=food1;
weight wt;
run;


Could you please help. Besides, it should be 'proc surveyfreq' and not just 'proc freq' as I am trying to generate estimates for entire population. And shouldn't the the third statement include status*sex as I am estimating the cross tabs?

Neil
Occasional Contributor P_J
Occasional Contributor
Posts: 10

Re: proc surveyfreq

Neil,

I'm no familiar with surveyfreq.

And if you want to get the percentages of each 'status' within a 'sex' group seperately. That means only one way, I think you can only define status in table statement. Otherwise status*sex should be two ways.

As my understanding you have to write table statements twice, one for one way percentage calculation, and the other one fore getting estimates. Like below..

proc ..;
tables status ...
tables sex*status ...;


PJ
Super Contributor
Posts: 338

Re: proc surveyfreq

Hi P.J.,

Splendid!

Your program preceded by proc sort generated the % s I was exactly looking for. It worked with proc surveyfreq as well, so you have saved my time tremendously.

Thank you very much.

These are the programs.

proc sort data=food;
by sex;
run;


proc surveyfreq data=food;
by sex ;
tables status ;
weight wt;
run;


Thanks

Neil
Ask a Question
Discussion stats
  • 6 replies
  • 297 views
  • 0 likes
  • 3 in conversation