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

Hi,

 

SAS can store date as a SAS numeric date like 20999. There are a lot of functions to format this value to a readable value like a MM/DD/YYYY format. 

 

My question is, how do you convert a formatted SAS date back to a SAS numeric date?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ

Hello,

 

A format is NOT a function.
It is just a part of the metadata for a variable that tells SAS how to display the internal value.

With or without format , the internal numeric value stays always the same.

 

To remove the format (such that internal value is shown as a number for your date-var) , do this :

proc datasets lib=mylib memtype=data;
   modify TableABC;
     attrib DateVarXYZ format=;
contents data=mylib.TableABC;
run;
quit;

Cheers,
Koen

View solution in original post

5 REPLIES 5
sbxkoenk
SAS Super FREQ

Hello,

 

A format is NOT a function.
It is just a part of the metadata for a variable that tells SAS how to display the internal value.

With or without format , the internal numeric value stays always the same.

 

To remove the format (such that internal value is shown as a number for your date-var) , do this :

proc datasets lib=mylib memtype=data;
   modify TableABC;
     attrib DateVarXYZ format=;
contents data=mylib.TableABC;
run;
quit;

Cheers,
Koen

cosmid
Lapis Lazuli | Level 10
Thanks for the quick reply! I wasn't expecting any replies on Christmas day!

I really appreciate the info. Now I know dates in SAS are always SAS numeric values (a number) and can be used in arithmetics (even if they are formatted). The formats and informats are just there for how they are displayed and stored.

Thanks again for the help and Merry Christmas!
sbxkoenk
SAS Super FREQ

Hello ,

 

I am glad you got it. 🙂

In SAS V9.4 , there are only 2 data types : character & numeric (dates are just formatted numeric values).

( In SAS VIYA , there are many more data types ... for CAS-tables ).

 

This sentence of yours might be a bit confusing :

The formats and informats are just there for how they are displayed and stored.

 

I would rather say :
The formats are just there for how they (the numbers) are displayed.

The informats are just there for how they are read and stored (as a number).

Cheers,

Koen

SASKiwi
PROC Star

SAS dates are numeric only and can optionally have a format applied:

28         data _null_;
29           SASDate = 20999;
30           format SASDate date9.;
31           put _all_;
32         run;

SASDate=29JUN2017 _ERROR_=0 _N_=1
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
cosmid
Lapis Lazuli | Level 10
Hi SASKiwi,

I actually wanted the opposite result, 29JUN2017 displayed as 20999. But now I know to do that is just to remove the formats. Thanks for the help though.

Merry Christmas!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 938 views
  • 4 likes
  • 3 in conversation