I have a data set that several variables that are numeric and have value label formats that are text. I am doing a proc freq with an output option and would like to stack these variables on top of each other while maintaining the 'text' value label and NOT the numeric value. Everytime I do this every output after the first variable will take on the value formats of the first variable. Is there a way to convert the value labels into the value??
Sorry, your post is confusing. Do you mean that when you set the datasets together the variable is set to the label of the first dataset - this is normal, as a variable can only have one name, and one label. Post example test data - in the form of a datastep - and what the output should look like, maybe if you want subheadings:
data want (keep=category); length category $20; set freq_out1 (in=a) freq_out2 (in=b); if a then do; category="Freq heading1"; output; category=cats(' ',put(n,best.)); output; end; if b then do; ... run;
This will output a row for the title of the variable, then the result (indented a bit).
hi! Thanks-- no I was actually talking about the value labels. Say I have two questions;
and then another question
I want my freq output file to look like:
but what I end up getting is something like:
because it is taking the format of the gender variable and applying it to ethnicity. so My thought was to somehow turn those value labels into the actual text values. Any ideas?????
proc freq data =dsn ;
tables gender\output out=dsn1 ;
data dsn1 ; set dsn1 ;
rename gender=value ;
proc freq data = dsn ;
tables ethnicity\output out=dsn2 ;
data dsn2 ; set dsn2 ;
rename ethnicity=value ;
data both ; set dsn1 dsn2 ;
I think the big question is can you change the value label into the value, so instead of the value being 1 can I make it be the label, e.g. female, male....
Well, the answer is per my post above. I have updated your code to read easily and commented below,
proc freq data=dsn; tables gender \ output out=dsn1; run; data dsn1; set dsn1; /* At this point, your dsn1 contains a variable called value, which has the attributes of gender */ rename gender=value; run; proc freq data=dsn; tables ethnicity \ output out=dsn2; run; data dsn2; set dsn2; /* At this point, your dsn1 contains a variable called value, which has the attributes of ethnicity */ rename ethnicity=value; run; data both; /* At this point you have two variables which are both numeric, but have different attributes, one with gender, one with ethinicity. As the gender one is first in the set statement its attributes are carried forward, hence value takes the format of gender */ set dsn1 dsn2; run ;
Basically a column can only have one set of properties - length, label, format, etc. Now as gender (value) is first in the set statement the format for gender is applied to the whole variable including the ethnicity values. The easiest way round this is to convert both to character and put them into the respective formats:
proc freq data=dsn; tables gender \ output out=dsn1; run; data dsn1;
length value $200; set dsn1; value=put(gender,gender.); run; proc freq data=dsn; tables ethnicity \ output out=dsn2; run; data dsn2;
length value $200; set dsn2; value=put(ethnicity,ethinicty.); run; data both; set dsn1 dsn2; run ;
You should now see a character field value which has the relevant values.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.