BookmarkSubscribeRSS Feed
robertrao
Quartz | Level 8

Hello,

 

I have the following code. In the gender dataset created Sex variable is still being outputted as 1 or 2 instead of being Male /Female.

genderkey is a charecter variable

 

Please suggest me if i went wrong?

 

data test1(rename=(genderkey=start name=label));

set gender_dataset(keep=genderkey name);

fmtname='genderfmt';

run;

proc format cntlin=test1;run;

 

 

START    LABEL     FMTNAME

1        Female    genderfmt

2        Male      genderfmt

 

data gender;

set have;

Sex=put(genderkey,genderfmt.);

run;

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

I assume from what you have given that SEX is numeric, hence it will not map to the character format created by the read in.  In test 1, convert genderkey to a number then it will create a number when read in as format.  Currently 1 != "1".  What you want is something like:

proc format;
value genderfmt
1="Female"
2="Male";
run;

data gender;
genderkey=1;
Sex=put(genderkey,genderfmt.);
run;

PGStats
Opal | Level 21

Try

data test1;
set gender_dataset;
start = input(genderkey, best.);
label = name;
fmtname = 'genderfmt';
keep start label fmtname;
run;

proc format cntlin=test1; run;
 
data gender;
set have;
Sex = put(genderkey, genderfmt.);
run;
PG

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!

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
  • 2 replies
  • 777 views
  • 0 likes
  • 3 in conversation