DATA Step, Macro, Functions and more

Formats

Reply
Super Contributor
Posts: 1,041

Formats

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;

Super User
Super User
Posts: 7,997

Re: Formats

Posted in reply to robertrao

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;

Respected Advisor
Posts: 4,934

Re: Formats

Posted in reply to robertrao

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
Ask a Question
Discussion stats
  • 2 replies
  • 176 views
  • 0 likes
  • 3 in conversation