Just getting started with an integration that will be using a SAS data file. I've figured out how to work with the 5 digit data values (Number of days before or after 1 Jan 1960).
Reviewing the list of variables and attributes, I found some date values that use a Number of length 4.
How does that work?
There are two different formats in use for these values:
DATE9.
YYMMN4.
Any help understanding this data is greatly appreciated.
Length as a variable property, not a format, refers to the number of bytes are used to store the value.
As long as the length is large enough to hold the values you need don't worry. Dates with length 4 or 5 will be okay. Other numeric values perhaps not depending on the range of values needed.
From the SAS documentation
Length in Bytes
|
Largest Integer Represented Exactly
|
Exponential Notation
|
Significant Digits Retained
|
---|---|---|---|
3
|
8,192
|
213
|
3
|
4
|
2,097,152
|
221
|
6
|
5
|
536,870,912
|
229
|
8
|
6
|
137,438,953,472
|
237
|
11
|
7
|
35,184,372,088,832
|
245
|
13
|
8
|
9,007,199,254,740,992
|
253
|
15
|
You can test the latest date or datetime value that can be stored by placing the "largest integer represented exactly" in to this code, in this case for length 4.
data _null_; x=2097152; put "as a date " x= date9. " as a datetime " x=datetime20.; run;
The log shows:
as a date x=23OCT7701 as a datetime x=25JAN1960:06:32:32
None of the date formats will display properly when the year exceeds 9999, which is why I picked the value for length=4.
Does it have a length of 4? With the LENGTH? Check via PROC CONTENTS.
You're showing different formats, not lengths.
YYMMN4 is a format that means a date like May 18, 2021 will show as 2105 (21 = YY, 05 = MM).
But the underlying data is still May 18th. You can change the format to see the underlying value.
How you deal with it depends on your objectives.
Here's a great, but longer and in depth, reference for dates and times in SAS
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/...
Thank you for the quick response and the helpful link. I don't have access to SAS software, so I can't answer your question. So far, I'm working with a data definition document:
With this one, the length attribute appears to refer to the stored data: a 5 digit number representing the days since 1 JAN 1960:
Here's the one I'm trying to figure out:
I understand that this isn't much to work with, but it's all I have at the moment. Thanks again.
Length as a variable property, not a format, refers to the number of bytes are used to store the value.
As long as the length is large enough to hold the values you need don't worry. Dates with length 4 or 5 will be okay. Other numeric values perhaps not depending on the range of values needed.
From the SAS documentation
Length in Bytes
|
Largest Integer Represented Exactly
|
Exponential Notation
|
Significant Digits Retained
|
---|---|---|---|
3
|
8,192
|
213
|
3
|
4
|
2,097,152
|
221
|
6
|
5
|
536,870,912
|
229
|
8
|
6
|
137,438,953,472
|
237
|
11
|
7
|
35,184,372,088,832
|
245
|
13
|
8
|
9,007,199,254,740,992
|
253
|
15
|
You can test the latest date or datetime value that can be stored by placing the "largest integer represented exactly" in to this code, in this case for length 4.
data _null_; x=2097152; put "as a date " x= date9. " as a datetime " x=datetime20.; run;
The log shows:
as a date x=23OCT7701 as a datetime x=25JAN1960:06:32:32
None of the date formats will display properly when the year exceeds 9999, which is why I picked the value for length=4.
Thank you for this comprehensive response. This is very helpful!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.