BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Lauban
Fluorite | Level 6
 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
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

@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

13 REPLIES 13
kiranv_
Rhodochrosite | Level 12

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

data abc;
a='11/May/2008';
b=input(a,date9.);
format b mmddyy10.;
run;
Lauban
Fluorite | Level 6

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

Jagadishkatam
Amethyst | Level 16
data have;
input date&:$20.;
new=input(compress(date,' /'),date9.);
format new mmddyy10.;
cards;
02 / Nov / 2007 
;
Thanks,
Jag
Lauban
Fluorite | Level 6

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 . 

Jagadishkatam
Amethyst | Level 16
Could you please let us know how is it not working, I mean the reason to provide a better solution.
Thanks,
Jag
Lauban
Fluorite | Level 6

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.  

Reeza
Super User

@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?

Lauban
Fluorite | Level 6

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.
Tom
Super User Tom
Super User

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.

Lauban
Fluorite | Level 6

 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!

Kurt_Bremser
Super User

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.

Jagadishkatam
Amethyst | Level 16
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
Tom
Super User Tom
Super User

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.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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