BookmarkSubscribeRSS Feed
Newtrix
Fluorite | Level 6

To begin with, I understand the basics of 1/1/1960 as the 'base' for all dates in SAS programming, so no need to elaborate on that.

What I don't understand is what my code is doing to change the dates back to that date from what I'm trying to input. Any guidance you may provide is greatly apprecated.

 

DATA study; SET chart;

IF Sequence_No_ = 'A01-02' THEN DO;

Best = 2; Best_Date = 09/11/2017; Prog_Date = 09/11/2017;

END;
ELSE IF Sequence_No_ = 'A01-03' THEN DO;

Best = 2; Best_Date = 11/28/2017; Prog_Date = 11/28/2017; END;

FORMAT Best_Date MMDDYY.10 Prog_Date MMDDYY10.

RUN;

 

What I get back is:

Sequence_No         Best_Date        Prog_Date

A01-02                    01-01-1960       01-01-1960

A01-03                    01-01-1960       01-01-1960

 

Again, I get the significance of 1-1-1960. All I need is the correct code so that I get the dates I want. Thanks!

2 REPLIES 2
quickbluefish
Barite | Level 11
It's because you're doing literal math with those things that look like dates:
11/28/2017 is 11 divided by 28 divided by 2017. You need to format the dates, e.g., like this: "28Nov2017"d -- SAS understands that as a date. There are other ways too.
Kurt_Bremser
Super User
Best_Date = 09/11/2017;

You do not assign a date here, but the result of a numeric expression: 9 divided by 11, then divided by 2017. This gives a very small number close to zero, which, when formatted as a date, will result in 1960-01-01.

To supply dates in code, you must use valid date literals:

Best_Date = "09nov2017"d;

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 508 views
  • 0 likes
  • 3 in conversation