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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 845 views
  • 0 likes
  • 4 in conversation