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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 1368 views
  • 0 likes
  • 4 in conversation