BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Emma_at_SAS
Lapis Lazuli | Level 10

I have a Date column that is numeric with format MMDDYY8. I want to modify one of the dates in my dataset. I tried the following code to change the date for a specific ID participant:

data want;

set have;

if IDvar eq "ABCD" then datevar = 03/08/20;

run;

Type   Ln    Format    
Num 8 MMDDYY8.

but instead of the date I want, I got  01/01/60

01/01/60

May you please help me solve this?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
You need to provide dates in a specific format, "08Mar2020"d -> I would always recommend using a 4 digit year as well.

if idvar = 'ABCD" then datevar = '08Mar2020'd;

Jump to the section on Dates/DateTimes here:
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/p0cq7f0icfjr8vn19vyunwmmsl7m.htm

View solution in original post

9 REPLIES 9
Reeza
Super User
You need to provide dates in a specific format, "08Mar2020"d -> I would always recommend using a 4 digit year as well.

if idvar = 'ABCD" then datevar = '08Mar2020'd;

Jump to the section on Dates/DateTimes here:
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/p0cq7f0icfjr8vn19vyunwmmsl7m.htm
PaigeMiller
Diamond | Level 26

You are close. Here is the way to do this:

 

if IDvar eq "ABCD" then datevar = '03AUG2020'd;

It has to be that exact syntax, except that it can be upper or lower or mixed case.

--
Paige Miller
Tom
Super User Tom
Super User

3 divided by 8 divided by 20 is 0.01875 which is less than 1.  So 01JAN1960 is the right date for the value you stored.

Did you intend to set the date to the 08MAR2020?  Or perhaps 08MAR1920? 

If so then you can either use a date literal (a quoted string that the DATE informat can read followed by the letter d) or a function that returns that date or the actual date value of 21982.

datevar = '08mar2020'd;
datevar = "8MAR2020"d;
datevar = '01-mar-2020'd;
datevar = mdy(3,8,2020);
datevar = 21982 ;

 

Emma_at_SAS
Lapis Lazuli | Level 10

Thank you, Reeza, , and Tom. All your answers were very helpful and I learned from each response.

 

Thanks!

PaigeMiller
Diamond | Level 26

Hello @Emma_at_SAS 

 

I'm glad you got an answer you can use.

 

If can make a suggestion, from now on you'd be better off using 4 digit years, rather than 2 digit years. This will avoid complications and confusion at some point in your programming career.

--
Paige Miller
Emma_at_SAS
Lapis Lazuli | Level 10
Thank you, PaigeMiller! I very much appreciate your advice! I agree that is great advice and I will follow that!
Emma_at_SAS
Lapis Lazuli | Level 10
Tom, may I ask how you calculated 21982?
Thanks!
Tom
Super User Tom
Super User

@Emma_at_SAS wrote:
Tom, may I ask how you calculated 21982?
Thanks!

Just ask SAS to show you.

208   data test;
209     x=mdy(3,8,20);
210     put x=;
211   run;

x=21982
Emma_at_SAS
Lapis Lazuli | Level 10
Great! Thanks!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 9 replies
  • 1056 views
  • 5 likes
  • 4 in conversation