BookmarkSubscribeRSS Feed
akkivsviddu
Calcite | Level 5

how we change the format like 

gender 0,1

to gender

0=male

1=female

5 REPLIES 5
akkivsviddu
Calcite | Level 5

how we change the format

for gender 

0=male

1=female

Kurt_Bremser
Super User

It's always a very good idea to provide usable test/example data (in a data step with datalines, see my footnotes for converting existing data to such a step, and how to post it).

So I have to guess that you have a numeric variable that only contains ones and zeroes.

Create a value format with proc format:

proc format lib=work;
value gender
  0 = 'male'
  1 = 'female"
;
run;

Then you can use that format, eg by assigning in a data step, or with proc print:

proc print data=have;
format sex gender.;
run;
divekarcm
Calcite | Level 5

Hi, 

If we take an example of class dataset... 

 

 

Proc sql;
create table class1 as
Select name,

case when sex='M' then 0 else 1 end as Sex ,

age,height,weight from sashelp.class;
Quit;

 

 

 

 

Capture1.PNGCapture2.PNG

 

 

And vice versa..

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Or if you don't want formats:

data want;
  set have;
  length genderc $20;
  if gender=0 then genderc="male";
  if gender=1 then genderc="female";
run;
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1688 views
  • 0 likes
  • 4 in conversation