Write and run SAS programs in your web browser

How to change string variable 11/May/2008 to date?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

How to change string variable 11/May/2008 to date?

[ Edited ]
 I want to change column a (olddate) which has character variables in the format of 11/May/2008 to a newdate column with the date variable with the format MM/DD/YYYY

Accepted Solutions
Solution
‎07-26-2017 02:30 AM
Super User
Posts: 19,789

Re: How to change string variable 11/May/2008 to date?


Lauban wrote:

Hi Jagadishkatam, I inputted

data VAT.T_FRMIMMUNEtwo;
set VAT.T_FRMIMMUNE;
datebloodsmeassured=input(compress(calmappeddov,' /'),date9.);
format calmappeddov mmddyy10.; 

But it did not work.  sorry about that.  


And did that generate an error? What did the log show?

View solution in original post


All Replies
PROC Star
Posts: 325

Re: How to change string variable 11/May/2008 to date?

use date9. informat to read and then use mmddyy10. format 

data abc;
a='11/May/2008';
b=input(a,date9.);
format b mmddyy10.;
run;
Occasional Contributor
Posts: 12

Re: How to change string variable 11/May/2008 to date?

Hi I received this:WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.   

Trusted Advisor
Posts: 1,137

Re: How to change string variable 11/May/2008 to date?

data have;
input date&:$20.;
new=input(compress(date,' /'),date9.);
format new mmddyy10.;
cards;
02 / Nov / 2007 
;
Thanks,
Jag
Occasional Contributor
Posts: 12

Re: How to change string variable 11/May/2008 to date?

Posted in reply to Jagadishkatam

Hi Jadagadish thanks for replying.  I want to change column a (olddate) which has character variables in the format of 11/May/2008 to a newdate column with the date variable with the format MM/DD/YYYY. Your code does not work for me, but I may have made a mistake . 

Trusted Advisor
Posts: 1,137

Re: How to change string variable 11/May/2008 to date?

Could you please let us know how is it not working, I mean the reason to provide a better solution.
Thanks,
Jag
Occasional Contributor
Posts: 12

Re: How to change string variable 11/May/2008 to date?

Posted in reply to Jagadishkatam

Hi Jagadishkatam, I inputted

data VAT.T_FRMIMMUNEtwo;
set VAT.T_FRMIMMUNE;
datebloodsmeassured=input(compress(calmappeddov,' /'),date9.);
format calmappeddov mmddyy10.; 

But it did not work.  sorry about that.  

Solution
‎07-26-2017 02:30 AM
Super User
Posts: 19,789

Re: How to change string variable 11/May/2008 to date?


Lauban wrote:

Hi Jagadishkatam, I inputted

data VAT.T_FRMIMMUNEtwo;
set VAT.T_FRMIMMUNE;
datebloodsmeassured=input(compress(calmappeddov,' /'),date9.);
format calmappeddov mmddyy10.; 

But it did not work.  sorry about that.  


And did that generate an error? What did the log show?

Occasional Contributor
Posts: 12

Re: How to change string variable 11/May/2008 to date?


1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
NOTE: ODS statements in the SAS Studio environment may disable some output features.
62
63 data VAT.T_FRMIMMUNEtwo;
64 set VAT.T_FRMIMMUNE;
NOTE: Data file VAT.T_FRMIMMUNE.DATA is in a format that is native to another host, or the file encoding does not match the session
encoding. Cross Environment Data Access will be used, which might require additional CPU resources and might reduce
performance.
65 datebloodsmeassured=input(compress(calmappeddov,' /'),date9.);
66 format calmappeddov mmddyy10.;
_________
484
NOTE 484-185: Format $MMDDYY was not found or could not be loaded.
Super User
Super User
Posts: 7,042

Re: How to change string variable 11/May/2008 to date?


Lauban wrote: 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
NOTE: ODS statements in the SAS Studio environment may disable some output features.
62
63 data VAT.T_FRMIMMUNEtwo;
64 set VAT.T_FRMIMMUNE;
NOTE: Data file VAT.T_FRMIMMUNE.DATA is in a format that is native to another host, or the file encoding does not match the session
encoding. Cross Environment Data Access will be used, which might require additional CPU resources and might reduce
performance.
65 datebloodsmeassured=input(compress(calmappeddov,' /'),date9.);
66 format calmappeddov mmddyy10.;
                       _________
                       484
NOTE 484-185: Format $MMDDYY was not found or could not be loaded.

 




 





Looks like it worked to me. You just attached the format to the old variable instead of the new one.  

 

Notice the $ that SAS added to the format in the note in the log. That is telling you that the variable you tried to attach the MMDDYY format to was a character varaible instead of numeric variable so SAS kindly decided that meant to attach a character format instead of a numeric format to it, but it couldn't find a character format with that name.

Occasional Contributor
Posts: 12

Changing text string to date

 I want to change column a (olddate) which has character variables in the format of 11/May/2008 to a newdate column with the date variable with the format MM/DD/YYYY. Thanks in advance!

Super User
Posts: 7,782

Re: Changing text string to date

Hi @Lauban!

Up to now you have failed to provide example data.

Use the macro provided in https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... to convert your dataset to a data step that can be posted here (use the 6th or 7th button on top of the posting window for posting code).

With an exact copy of your data (that's what the macro does), we can give you code that works with it.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Trusted Advisor
Posts: 1,137

Re: How to change string variable 11/May/2008 to date?

I agree with what @Tom mentioned that you applied the format to character variable calmappeddov, instead you should use the variable datebloodsmeassured. Could you please check this
Thanks,
Jag
Super User
Super User
Posts: 7,042

Re: How to change string variable 11/May/2008 to date?

[ Edited ]

Seems like the DATE informat can read those values, as long as you only have 3 characters for the month. Just make sure to use a large enough width.  If you have strings longer than three characters for the month name then you will probably want to use the ANDTDTE informat instead.

 

 

data _null_;
  input string $20. ;
  length informat $20 date 8;
  do informat='date20.','anydtdte20.';
    date=inputn(string,informat);
    put informat= date= date9. ;
  end;
cards;
02 / Nov / 2007
;
informat=date20. date=02NOV2007
informat=anydtdte20. date=02NOV2007

Not sure why you would want to display using mmddyy format as that is just asking for confusion when trying to communicate with people in the EU.  Why not use YYMMDD format instead so that nobody confusing Dec 10th for Oct 12th.  or use DATE9 since then the month is displayed using letters so again you cannot get confused about which number is the month and which is the day.

 

☑ This topic is solved.

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

Discussion stats
  • 13 replies
  • 399 views
  • 3 likes
  • 6 in conversation