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. 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 634 views
  • 0 likes
  • 2 in conversation