SAS Procedures

Help using Base SAS procedures
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Martinez77
Fluorite | Level 6

Hey all,

I am trying to format a date variable that currently has a date16 format.

There are . for missing values for the variable. I need to reformat this but I get an ERROR: There was a problem with the format so BEST. was used.

Not sure what is going on. or how to work around.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
CTorres
Quartz | Level 8

Try this to reformat "mydate":

mydate=datepart(mydate);
put mydate mmddyyn8.;

Regards,

View solution in original post

7 REPLIES 7
Reeza
Super User

What does date16. look like? In my version of SAS date9. is the biggest format I can have.

Post what your dates currently look like and what you want them to look like, eg. reformat to.

Martinez77
Fluorite | Level 6

Reeza

29MAR2013:00:00:00

This is what they currently look like.

I want it to appear like this: 03292013

Thanks you for your help,

Martinez77

CTorres
Quartz | Level 8

Try this to reformat "mydate":

mydate=datepart(mydate);
put mydate mmddyyn8.;

Regards,

Martinez77
Fluorite | Level 6

I should have been a little more clear.

I have a variable in my data set name enrl_drop_dt which contains date values as below:

29MAR2013:00:00:00

There are missing values with a . if missing.

I need them to display as shown below:

03292013

I was hoping I could do it in a data step

Data bla;

set bla;

format enrl_drop_dt mmddyyy6.;

run;

I hope that shines some light

Thanks,

Martinez

Astounding
PROC Star

The format to use would be:

mmddyyn8.

There is some question as to whether that would apply as is, or whether you need to change your data as well:

enrl_drop_dt = datepart(enrl_drop_dt);

It all depends on what your variable contains.  If it's a date variable, leave it as is.  If it's a date-time variable, you'll have to apply DATEPART.  So try it with just the format and see how the dates look.  If they are far too large, apply DATEPART.

Martinez77
Fluorite | Level 6

all

Thank you all very much. I had a typo in my format. Fixed it and the datepart function worked great.

Another sas win.

Thanks,

Martinez

Reeza
Super User

So your variable is actually a datetime variable, not a date variable.

You can use some date formats specifically on datetime variables, but the one you require isn't...AFAIK. That leaves you with two options, 1) Recode your variable to a true date variable so you can apply the date variable or 2) Create your own format that you can apply. 

The first option was suggested by CTorres above in a data step.  The second partly depends on what version of SAS you have, do you have SAS 9.3. In SAS 9.3 you can use functions in a format so it becomes relatively straight forward then.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 3456 views
  • 6 likes
  • 4 in conversation