BookmarkSubscribeRSS Feed
ammarhm
Lapis Lazuli | Level 10

A simple question

I have a dataset containing a variable 'Sex', with values 1 and 2 (this is a numerical variable)

I want to change the contents of the variable to Female if Sex=1 and Male if Sex =2.

So the type of the variable will need to be changed too

Any simple way of doing it (without creating a temporary dummy variable?)

Best wishes

3 REPLIES 3
mohamed_zaki
Barite | Level 11

It is the way mentioned in sas doc

Sample 24590: Convert values from character to numeric or from numeric to character

may i ask what is the problem with this way?

You can do the convert also in PROC SQL

check this old thread

KachiM
Rhodochrosite | Level 12

Not sure of your question.

Do you want a solution like this?

proc format;

value num2ch 1 = 'Female'

             2 = 'Male'

             ;

run;

data have;

input Sex;

datalines;

1

1

2

2

1

2

;

run;

data want;

   set have;

   format Sex num2ch.

run;

proc print data = want;

run;

proc contents data = want;

run;

But the type of SEX is still Number in WANT data set.

Reeza
Super User

Not really without temporary variables. 

You can use a format to change the display, depending on what you're doing, a Class statement in many procs will accomplish this automatically.

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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1555 views
  • 0 likes
  • 4 in conversation