BookmarkSubscribeRSS Feed
CJxyz
Calcite | Level 5

Hello,

I'm trying to get into SAS programing and I'm having a lil trouble separating categories in my variable age (<15, 16-17, >18 years old).  I need to used proc surveymeans but the output only shows all 3 categories together and 1 mean in 1 row.  How you I get the output to show 3  means in the separate rows?

Thank you for helping 

Screenshot (16).jpg

Code:

age_new =.;

if age le 15 then age_new =1;
if age = 16 or age = 17 then age_new =2;
if age ge 18 then age_new =3;

 

label
age_new = "1=15 or Under" "2=Between 16-17" "3=18 or Older"

run;

 

proc format;
value age_new 1='1=15 or Under' 2='2=16 or 17' 3='3=18 or Older';

run;

 

proc surveymeans data=syc mean clm sum std stderr clsum plots=none;
stratum stratum;
cluster psu;
weight finalwt;
var age_new;

run;

1 REPLY 1
ballardw
Super User

Your code requested the mean and other statistics of a variable. It does nothing to use levels.

In Surveymeans variables that used for categories belong in a DOMAIN statement. At which point the mean for age_new will be the value of age_new. Are you sure that you aren't looking for SURVEYFREQ to estimate percentages of age_new?

Or is there another actual variable that you want the mean and other statisics for such as height, test score or such that would belong on the VAR variable?

If you want the actual mean Age within the Age_new group that would be:

proc surveymeans data=syc mean clm sum std stderr clsum plots=none;
stratum stratum;
cluster psu;
weight finalwt;
domain age_new;
var age;

run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 222 views
  • 0 likes
  • 2 in conversation