BookmarkSubscribeRSS Feed
Xinxin
Obsidian | Level 7

Here is my code which works fine in numerous different places but not at one point:

 

PROC MEANS DATA=AGE_GRP NOPRINT NWay

;

CLASS TIME_PERIOD MARKET ;

VAR age;

OUTPUT OUT=AGE_UNWTDMEANS(DROP=_TYPE_ _FREQ_) n=BASE_UNWTD SUM=CNT_UNWTD MEAN=PER_UNWTD;

RUN
;

The output dataset gives the variable names correctly as BASE_UNWTD, CNT_UNWTD AND PER_UNWTD but the labels for these variables is "AGE" and I want it to be the same as the variable name.

I have used the EXACT same code for a different variable and it works !!

(Sorry if this ques is too basic but I'm having a hard time giving the correct labels to variables in the output dataset.)

Thanks!

6 REPLIES 6
art297
Opal | Level 21

When I run your code I do get the same names for both variable names and labels.

FriedEgg
SAS Employee

proc means data=sashelp.heart noprint nway;

class status sex;

var ageatstart;

output out = want ( drop  = _: )

        n=base_unwtd

        sum=cnt_unwtd

        mean=per_unwtd /autolabel;

run;

*** /autolabel will append the original variable label with the stat calculated i.e.. AgeAtStart_N;

proc means data=sashelp.heart noprint nway;

class status sex;

var ageatstart;

output out = want ( drop  = _: )

        n=base_unwtd

        sum=cnt_unwtd

        mean=per_unwtd /noinherit;

run;

*** /noinherit will leave the label null;

Xinxin
Obsidian | Level 7

Thanks! The /noinherit worked in the sense that all the variables didn't come up as AGE in the output dataset as the labels were null.

I would've liked the labels to also be BASE_UNWTD, CNT_UNWTD and PER_UNWTD ........ but your option will work for now. Thanks,again!

art297
Opal | Level 21

I learned something new from your post as I didn't realize that proc means would assign the variable label as the labels in code like yours UNLESS one uses the noinherit option.

That is probably why it worked for all of your other variables .. they didn't have labels explicitly assigned.

FriedEgg
SAS Employee

When you do not define the noinherit option (the default would be inherit) more than just the label of the former variable is actually copied.  I believe it takes on all of the original variables attributes, including: label, format and possibly length?

EDIT:  I looked it up (http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000146734.htm) the length is not inheritied unless the inherit option is explicitly called.  Similar to the keeplen option this could probably cause numeric impressision...

DrAbhijeetSafai
Lapis Lazuli | Level 10
noinherit works!
Dr. Abhijeet Safai
Certified Base and Clinical SAS Programmer
Associate Data Analyst
Actu-Real

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 12346 views
  • 4 likes
  • 4 in conversation