date conversion

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

date conversion

I have dates comming in as char 02-mar-49, how do i read this date in and output it to yymmddn8.

 

Thank you


Accepted Solutions
Solution
‎02-29-2016 08:14 PM
Super User
Super User
Posts: 6,848

Re: date conversion

Use DATE9. as the INFORMAT and YYMMDDN8. as the format.

So if you are reading from a text file:

data want ;
   infile 'myfile' ;
   input mydate date9.;
   format mydate yymmddn8.;
run;

If you already have the value in a character variable then you can use INPUT function to convert it to an actual date.

mydate=input(mystr,date9.);

If you want to write it back to another character variable then use the PUT function.

mystr2 = put(mydate,yymmddn8.);

View solution in original post


All Replies
Solution
‎02-29-2016 08:14 PM
Super User
Super User
Posts: 6,848

Re: date conversion

Use DATE9. as the INFORMAT and YYMMDDN8. as the format.

So if you are reading from a text file:

data want ;
   infile 'myfile' ;
   input mydate date9.;
   format mydate yymmddn8.;
run;

If you already have the value in a character variable then you can use INPUT function to convert it to an actual date.

mydate=input(mystr,date9.);

If you want to write it back to another character variable then use the PUT function.

mystr2 = put(mydate,yymmddn8.);
Contributor
Posts: 20

Re: date conversion

Thank youSmiley Happy
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 302 views
  • 1 like
  • 2 in conversation