BookmarkSubscribeRSS Feed
Obsidian | Level 7

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


Thank you!!!

Diamond | Level 26 RW9
Diamond | Level 26

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";
    category=cats('  ',put(n,best.));
  if b then do;

This will output a row for the title of the variable, then the result (indented a bit).

Obsidian | Level 7

hi! Thanks-- no I was actually talking about the value labels. Say I have two questions;





and then another question


1= hispanic


3= asian...



I want my freq output file to look like:

value   count

female  4

male     6

black   2

hispanic 7

asian     1



but what I end up getting is something like:

value  count

female   4

male      6

female   2

male      7



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


Thank you!


Super User

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

Obsidian | Level 7

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 ;


run ;


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




Diamond | Level 26 RW9
Diamond | Level 26

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;

data dsn1; 
  set dsn1;
/* At this point, your dsn1 contains a variable called value, which has the attributes of gender */
  rename gender=value;
proc freq data=dsn;
  tables ethnicity \ output out=dsn2;

data dsn2;
  set dsn2;
/* At this point, your dsn1 contains a variable called value, which has the attributes of ethnicity */
  rename ethnicity=value;
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;

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.

Super User

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



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. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 3 in conversation