Character to Date

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

Character to Date

Hi,

 

I am trying to  change a Charcter to a Date in SAS EG and have tried code found on other threads as follows.

 

Data TestLive4;
Set TestLive3;
Format LAstPD date8.;
LastPD = Input(chardate,yymmdd8.);
run;

 

This however returns the following error message.

 

I have attached a screen print of the data and properties.

 


Accepted Solutions
Solution
‎12-20-2016 10:10 AM
Super User
Posts: 5,516

Re: Character to Date

[ Edited ]
Posted in reply to Kelvin156

If that is your incoming character data, you will need a new name for the new variable.  For example:

 

new_var = input(LastPD, yymmdd8.);

format new_var mmddyys10.;

View solution in original post


All Replies
Super User
Posts: 19,855

Re: Character to Date

Posted in reply to Kelvin156

It's usually DATE9, note date8

 

You don't show the error. Does a variable lastPD already exist? 

Super User
Posts: 5,516

Re: Character to Date

Posted in reply to Kelvin156

The most important information you could supply is what's actually in CHARDATE.  Just one or two examples would be fine.

Super User
Super User
Posts: 7,074

Re: Character to Date

Posted in reply to Kelvin156

Please don't post photographs of text. Just highlight the text of the error message and copy and paste it into you message.

 

Contributor
Posts: 52

Re: Character to Date

Posted in reply to Kelvin156

I don't think it results in an error. can you please share an example of input date value(LAstPD)?


Cheers from India!

Manjeet
Occasional Contributor
Posts: 6

Re: Character to Date

Posted in reply to Kelvin156

Apologies all,

 

The column name is LastPD and the data is in the following format. i want this to be formated as 13/12/2016 etc

 

LastPD
20161213
20160712
20160412
20161214
20130828
Solution
‎12-20-2016 10:10 AM
Super User
Posts: 5,516

Re: Character to Date

[ Edited ]
Posted in reply to Kelvin156

If that is your incoming character data, you will need a new name for the new variable.  For example:

 

new_var = input(LastPD, yymmdd8.);

format new_var mmddyys10.;

Occasional Contributor
Posts: 6

Re: Character to Date

Posted in reply to Astounding
Thank you, this has worked perfectly
Occasional Contributor
Posts: 6

Re: Character to Date

Posted in reply to Kelvin156

This is an extract ftrom the LOG, it also is formatting ALL of the values in LPD to .

 

 

15 Data TestLive4;
16 Set TestLive3;
17 Format LAstPD mmddyys10.;
__________
484
NOTE 484-185: Format $MMDDYYS was not found or could not be loaded.

18 LastPD = Input(chardate,yymmdd8.);
19 run;

Super User
Posts: 5,516

Re: Character to Date

Posted in reply to Kelvin156

LastPD is a character variable.  You cannot format it with a date format such as mmddyys10.

 

Instead, you have to create a new variable, and format the new variable.  My previous post illustrated how to do that.

 

☑ This topic is solved.

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

Discussion stats
  • 9 replies
  • 266 views
  • 2 likes
  • 5 in conversation