BookmarkSubscribeRSS Feed
simonm
Calcite | Level 5

Hi,

I'm attempting to do what I thought was something simple, i.e. calculated the mean and weighted mean of a variable in Proc Report by using an alias.

I'm running up against an unexpected issue whereby both columns are showing the same numbers, with the calculation apparently being based on the order in which the columns appear (I've renamed the variable weight in the data set to mass for clarity's sake):

/* Both columns calculated unweighted */

proc report data=sashelp.class(rename=weight=mass);

columns sex n height height=height_weighted;

define sex/group;

define height/'Height' mean;

define height_weighted/'Height (weighted)' mean weight=mass;

run;

/* Both columns calculated weighted */

proc report data=sashelp.class(rename=weight=mass);

columns sex n height=height_weighted height;

define sex/group;

define height/'Height' mean;

define height_weighted/'Height (weighted)' mean weight=mass;

run;

The only way I've found to get the right result is to create a copy of the variable in a data step and use that.

/* Create a copy of the variable */

data sashelp_class;

set sashelp.class;

height_weighted=height;

run;

/* Both columns calculated correctly */

proc report data=sashelp_class(rename=weight=mass);

columns sex n height height_weighted;

define sex/group;

define height/'Height' mean;

define height_weighted/'Height (weighted)' mean weight=mass;

run;

Is there another (hopefully less inelegant) way to get the result I'm looking for?

Thanks,

Simon.

1 REPLY 1
Cynthia_sas
SAS Super FREQ

Hi:

  If you look in the doc, it explains that WEIGHT= cannot be applied to an alias. So that is probably why your alias method did not work.

cynthia

Base SAS(R) 9.4 Procedures Guide, Third Edition

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 975 views
  • 0 likes
  • 2 in conversation