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
Pyrite | Level 9
noinherit works!
Dr. Abhijeet Safai
Associate Data Analyst
Actu-Real

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 11446 views
  • 4 likes
  • 4 in conversation