I am trying to convert the character variable "GenderCd" to a numeric variable. In order to apply a numeric format 'GenderCd.' I have tried using the INPUT statement to convert the variable into a numeric one, but it doesn't seem to be working properly. I'm not sure what I'm doing incorrectly.
This is the following code I've input into SAS:
DATA WORK.Demog_IA;
KEEP SSN GenderCd EthCd RaceCd EthRaceCd BirthDt;
SET IowaResidents;
LENGTH SSN $11
GenderCd
EthCd $1
RaceCd $1
EthRaceCd $3;
Gender = INPUT(Sex,1.);
Gender= PROPCASE(Sex);
IF Gender = 'Male' THEN GenderCd = 1;
ELSE IF Gender = 'Female' Then GenderCd = 2;
IF MISSING(Ethnicity) = 1 THEN EthCd = ' ';
ELSE IF Ethnicity = 'HISPANIC' THEN EthCd = 'H';
ELSE IF Ethnicity = 'NON-HISPANIC' THEN EthCd = 'N';
Else EthCd = 'U';
IF MISSING(Race) = 1 THEN RaceCd = ' ';
ELSE IF Race = 'WHITE' THEN RaceCd = 'W';
ELSE IF Race = 'BLACK' THEN RaceCd = 'B';
ELSE IF Race = 'ASIAN' THEN RaceCd = 'A';
ELSE IF Race = 'OTHER' THEN RaceCd = 'O';
ELSE RaceCd = 'U';
IF MISSING(EthCd) = ' ' AND RaceCd = ' ' THEN EthRaceCd = ' ';
ELSE IF EthCd = 'H' THEN EthRaceCd = 'HIS';
ELSE IF RaceCd = 'A' THEN EthRaceCd = 'NHA';
ELSE IF RaceCd = 'B' THEN EthRaceCd = 'NHB';
ELSE IF RaceCd = 'W' THEN EthRaceCd = 'NHW';
ELSE IF RaceCd = 'O' THEN EthRaceCd = 'NHO';
ELSE EthRaceCd = '.';
RUN;
PROC PRINT DATA = WORK.Demog_IA;
FORMAT GenderCd GenderCd.
EthCd $EthCd.
RaceCd $RaceCd.
EthRaceCd $EthRaceCd.
BirthDt MMDDYY10.;
RUN;
When I attempt to apply the format to the variables I receive the following error message:
ERROR: You are trying to use the numeric format GENDERCD with the character variable GenderCd in data set WORK.DEMOG_IA.