DATA Step, Macro, Functions and more

convert text to date

Reply
New Contributor
Posts: 2

convert text to date

I am a beginner. I am trying to used input to convert text to date, here is my function

input('Jul-17', MONYY5.)

The result is Jul01, same month but the year is wrong.

 

please help

Super User
Posts: 23,771

Re: convert text to date

5 is the length but  text is 6 characters. Remove the -  

 

You can remove the dash with the COMPRESS() function if needed. 

 


@linc wrote:

I am a beginner. I am trying to used input to convert text to date, here is my function

input('Jul-17', MONYY5.)

The result is Jul01, same month but the year is wrong.

 

please help


 

New Contributor
Posts: 2

Re: convert text to date

great thanks, the result is perfect Smiley Very Happy

input(compress('text',"-"),MONYY)

PROC Star
Posts: 1,833

Re: convert text to date

data w;
date=input('Jul-17', MONYY7.);
format date date9.;
run;
Regular Contributor
Posts: 164

Re: convert text to date

data test;
  monthtext="January";
  month=month(input("01"||substr(monthtext,1,3)||"2000",date9.));
run;

from stackoverflow: https://stackoverflow.com/questions/9300020/sas-format-full-month-name-to-integer

--------------
blog: papersandprograms.com
Ask a Question
Discussion stats
  • 4 replies
  • 73 views
  • 0 likes
  • 4 in conversation