10-17-2016 11:40 AM
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??
10-17-2016 12:52 PM
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).
10-17-2016 01:04 PM
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?????
10-17-2016 01:24 PM
Please show the code you are using.
You symptom does look possible a FORMAT statement has a problem, possibly Format gender race Genderformat. RaceFormat;
which should be
Format gender genderformat. race raceformat. ;
10-17-2016 01:49 PM
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....
10-17-2016 02:12 PM
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.
10-17-2016 02:46 PM
Perhaps starting more from scratch.
Consider what this result looks like:
proc tabulate data=dsn; class gender ethnicity; table gender ethnicity, n colpctn ; format gender gender. ethnicity ethnicity.; run;