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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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