BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sdang
Quartz | Level 8

Hi,

I created a new column with only Today() function.  However, it returns the date as of 01Jan1960, not today's date.

 

Any idea?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
The function is working properly, please read up on how SAS stores dates, as number of days from January 1, 1960. So it's been 20445 days since Jan 1, 1960. To view as a date, apply the desired format.

Change to your code:
TODAY() AS Today format=date9.

Example demonstration:
data _null_;

x=today();

y=x;
format y date9.;

put "Unformatted:" x "Formatted:" y;
run;


View solution in original post

6 REPLIES 6
SASKiwi
PROC Star

Please supply your complete program. One possibility is that the variable you are assigning TODAY() to is fomatted as a DATETIME not as a DATE. Without your code we would just be guessing. 

sdang
Quartz | Level 8

 

Hi, below are the codes.  This time I did not formatt it.  The number SAS gives me for every available row is 20445. I also attached a image of the result it gave me.

 

PROC SQL;

CREATE TABLE WORK.QUERY_FOR_THE_SEASON_PARTIC_0002 AS

SELECT t1.GuestNumber1,

/* COUNT_of_GuestNumber1 */

(COUNT(t1.GuestNumber1)) AS COUNT_of_GuestNumber1,

/* Calculation */

(TODAY()) AS Today()

FROM WORK.QUERY_FOR_THE_SEASON_PARTIC_0000 t1

GROUP BY t1.GuestNumber1,

(CALCULATED Calculation);

QUIT;

 

Capture.PNG

SASKiwi
PROC Star
PROC SQL;
 
CREATE TABLE WORK.QUERY_FOR_THE_SEASON_PARTIC_0002 AS
 
SELECT t1.GuestNumber1, 

/* COUNT_of_GuestNumber1 */
 
(COUNT(t1.GuestNumber1)) AS COUNT_of_GuestNumber1, 

/* Calculation */
 
TODAY() AS Today format = date9.
FROM WORK.QUERY_FOR_THE_SEASON_PARTIC_0000 t1 GROUP BY t1.GuestNumber1, (CALCULATED Calculation); QUIT;
sdang
Quartz | Level 8

Hi, I wrote your codes now but it still gives me the same result--see image below.

Below are the codes:

PROC SQL;

CREATE TABLE WORK.QUERY_FOR_FILTER_FOR_QUERY__0003 AS

SELECT t1.GuestNumber,

/* COUNT_of_GuestNumber */

(COUNT(t1.GuestNumber)) AS COUNT_of_GuestNumber,

/* Today */

TODAY() AS Today

FROM WORK.QUERY_FOR_FILTER_FOR_QUERY_FOR_T t1

GROUP BY t1.GuestNumber,

(CALCULATED Today);

QUIT;

 

Thank you

Capture.PNG

 

Reeza
Super User
The function is working properly, please read up on how SAS stores dates, as number of days from January 1, 1960. So it's been 20445 days since Jan 1, 1960. To view as a date, apply the desired format.

Change to your code:
TODAY() AS Today format=date9.

Example demonstration:
data _null_;

x=today();

y=x;
format y date9.;

put "Unformatted:" x "Formatted:" y;
run;


SASKiwi
PROC Star

As Reeza has stated you left off FORMAT = date9.

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
  • 6 replies
  • 74534 views
  • 0 likes
  • 3 in conversation