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!
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
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
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
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
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!
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.