Help using Base SAS procedures

How to get labels in proc means output dataset ?

Reply
Contributor
Posts: 40

How to get labels in proc means output dataset ?

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!

PROC Star
Posts: 7,474

How to get labels in proc means output dataset ?

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

Trusted Advisor
Posts: 1,301

How to get labels in proc means output dataset ?

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;

Contributor
Posts: 40

How to get labels in proc means output dataset ?

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!

PROC Star
Posts: 7,474

How to get labels in proc means output dataset ?

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.

Trusted Advisor
Posts: 1,301

Re: How to get labels in proc means output dataset ?

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...

Ask a Question
Discussion stats
  • 5 replies
  • 1494 views
  • 0 likes
  • 3 in conversation