BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lthompson1
Calcite | Level 5

Hi everyone, 

 

I'm having some trouble converting a date variable in a character format to a numeric format.

 

The data is currently looks like this and is specified as a character variable, ex:

30AUG1951

 

I would like to convert this to MMDDYY10 numeric format. 

 

Here is what my code looks like now:

 

DATA	WORK.Demog_MS;
	SET	HypImpt.MS_Citizens;

	BirthDt	= INPUT(DOB, 10.);
	FORMAT BirthDt MMDDYY10.;
	DROP DOB;
	SSN		=	SocSecNum;
	LENGTH	SSN			$11	
			GenderCd	 8	
			EthCd		$1
			EthRaceCd	$3;
			
	LABEL	SSN			=	'Social Security Number'
			GenderCd	=	'Gender Code'
			EthCd		=	'Ethnicity Code'
			RaceCd		=	'Race Code'
			EthRaceCd	=	'Ethnicity/Race Code'
			BirthDt		=	'Birth Date';

	IF 		Gender			=	'Male'				THEN	GenderCd	=	1;
	ELSE IF Gender			=	'Female'			THEN	GenderCd	=	2; 

	IF Eth				=	'Hispanic or Latino'		THEN				EthCd		=	'H';
	ELSE IF Eth			=	'Not Hispanic or Latino'	THEN				EthCd		=	'N';
	
	IF Racial		=	'Caucasian'					THEN				RaceCd		=	'W';
	ELSE IF Racial		=	'African American'			THEN				RaceCd		=	'B';
	ELSE IF Racial		=	'Asian'						THEN				RaceCd		=	'A';
	ELSE IF Racial		=	'Other Race'				THEN				RaceCd		=	'O';

	IF Eth				=	'Hispanic or Latino'		THEN												EthRaceCd	=	'HIS';
	ELSE IF Eth			=	'Not Hispanic or Latino'	AND		Racial		=	'Asian'				THEN	EthRaceCd	=	'NHA';
	ELSE IF Eth			=	'Not Hispanic or Latino'	AND		Racial		=	'African American'	THEN	EthRaceCd	=	'NHB';
	ELSE IF Eth			=	'Not Hispanic or Latino'	AND		Racial		=	'Other'				THEN	EthRaceCd	=	'NHO';
	ELSE IF Eth			=	'Not Hispanic or Latino'	AND		Racial		=	'Caucasian'			THEN	EthRaceCd	=	'NHW';

RUN;

 

Are there better methods I could utilize to create the desired format? 

 

Thank you so much in advance for your help! 

1 ACCEPTED SOLUTION
2 REPLIES 2
lthompson1
Calcite | Level 5

Thank you so much! This fixed the problem.