BookmarkSubscribeRSS Feed
Mirisage
Obsidian | Level 7
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
6 REPLIES 6
1162
Calcite | Level 5
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]
Mirisage
Obsidian | Level 7
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
P_J
Calcite | Level 5 P_J
Calcite | Level 5
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;
Mirisage
Obsidian | Level 7
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
P_J
Calcite | Level 5 P_J
Calcite | Level 5
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
Mirisage
Obsidian | Level 7
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

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
  • 6 replies
  • 1311 views
  • 0 likes
  • 3 in conversation