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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

Significant Digits and Largest Integer by Length for SAS Variables under Windows
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.

 

 

View solution in original post

4 REPLIES 4
Reeza
Super User

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

SAS44
Fluorite | Level 6

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:

SAS_snippet1.png

 

With this one, the length attribute appears to refer to the stored data: a 5 digit number representing the days since 1 JAN 1960:

SAS_snippet2.png

 

Here's the one I'm trying to figure out:

SAS_snippet.png

 

I understand that this isn't much to work with, but it's all I have at the moment.  Thanks again.

 

 

 

ballardw
Super User

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

Significant Digits and Largest Integer by Length for SAS Variables under Windows
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.

 

 

SAS44
Fluorite | Level 6

Thank you for this comprehensive response.  This is very helpful!

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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
  • 4 replies
  • 2971 views
  • 2 likes
  • 3 in conversation