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;
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!
When I run your code I do get the same names for both variable names and labels.
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;
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!
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.
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...
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.