Help using Base SAS procedures

Converting MMDDYYCC(character) to CCYYMMDD(numeric)

Reply
Occasional Contributor
Posts: 6

Converting MMDDYYCC(character) to CCYYMMDD(numeric)


I have a date field that is defined as character(MMDDYYCC).

Example: 11301220(Novermber 30th, 2012)

Could anyone please help me to convert this to CCYYMMDD in Numeric value?

The result should look like this: 20121130.

The reason why I need this in Numeric value is to sort this data.

Thank you for your help in advance!!

Respected Advisor
Posts: 3,124

Re: Converting MMDDYYCC(character) to CCYYMMDD(numeric)

Try this:

data have;

input date$12.;

date1=input(cats(substr(date,1,4),substr(date,7,2),substr(date,5,2)),mmddyy10.);

format date1 yymmddn8.;

cards;

11301220

12011221

;

proc print;run;

Haikuo

Occasional Contributor
Posts: 6

Re: Converting MMDDYYCC(character) to CCYYMMDD(numeric)

Hi Haikuo,

Thank you very much for the prompt response. I really appreciate it.

The thing is I'm completely new to SAS Enterprise Guide pr SAS and I was trying to use your code in the "Computed Columns" like this:

input(cats(substr(date,1,4),substr(date,7,2),substr(date,5,2)),mmddyy10.):

format date yymmddn8.:

And it gave me an error.

Would it be possible for you to tell me how I can do this in the Enterprise Guide screen?

Thank you very much!!

Respected Advisor
Posts: 3,124

Re: Converting MMDDYYCC(character) to CCYYMMDD(numeric)

sorry. I am among those old school SAS programmers who are NOT the targeting populations of EG. I have never used EG myself even I know it has been installed on my pc. I am sure someone on the forum with EG experience will surely come to rescue.

On a side note, if you have posted your question on EG board, I would probably have never responded.

Good Luck,

Haikuo

Occasional Contributor
Posts: 6

Re: Converting MMDDYYCC(character) to CCYYMMDD(numeric)

Hai.kuo,

Thank you for the info.

I didn't realze that there is a separate forum for SEG.

I really appreciate your help!!Smiley Happy

Ask a Question
Discussion stats
  • 4 replies
  • 1131 views
  • 0 likes
  • 2 in conversation