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

Hi All,

 

I have the following set of numeric dates which I need to convert into a date format

 

10161
10164
10168
10169
10170
10171
 
for example the first value represent 01JAN1961 but some values can represent dates in this century too.
 
I have attempted 
DATE = Input( Put( MyDate, 8.), date9.
but have failed.
 
Any help will be appreciated
 
Thanks in advance !
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Important clarification: the values are numeric, but they are not SAS date values. SAS date values are the number of days since 01JAN1960, and so January 1, 2020 is represented as 21915 in SAS.

 

Important clarification: when you provide dates, the first part of the date (either day or month, it's not clear which this is from your description) must be TWO digits.

 

So, in your cases, you can use the Z6. format on 10161, making the first part of the date now having two digits, and then the code should work

 

data a;
    mydate=10161;
    DATE = put( mydate, z6.);
    numdate = input(date,mmddyy6.);
    format numdate date9.;
run;

 

and also you must clarify does date come first or does month come first in your inputs.

 

Lastly:

 

I have attempted 
DATE = Input( Put( MyDate, 8.), date9.
but have failed.
 
This code can't possibly work, it has unbalanced parentheses and is missing a semicolon.

 

 

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Important clarification: the values are numeric, but they are not SAS date values. SAS date values are the number of days since 01JAN1960, and so January 1, 2020 is represented as 21915 in SAS.

 

Important clarification: when you provide dates, the first part of the date (either day or month, it's not clear which this is from your description) must be TWO digits.

 

So, in your cases, you can use the Z6. format on 10161, making the first part of the date now having two digits, and then the code should work

 

data a;
    mydate=10161;
    DATE = put( mydate, z6.);
    numdate = input(date,mmddyy6.);
    format numdate date9.;
run;

 

and also you must clarify does date come first or does month come first in your inputs.

 

Lastly:

 

I have attempted 
DATE = Input( Put( MyDate, 8.), date9.
but have failed.
 
This code can't possibly work, it has unbalanced parentheses and is missing a semicolon.

 

 

--
Paige Miller
mkeintz
PROC Star

I take it that the last 2 digits are the year, the next 2 digits to the right left of the year is the day-of-month (even if the day-of-month is less than 10), and the leading 1 (or 2) digits is the month, correct?  In other words, your values are either 5 or 6 digits, depending on the month.

 

What is the cutoff value for years assigned to the 20th century (19xx) and years in the 21st century?

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Kurt_Bremser
Super User

Can you be sure about DMY or MDY order? And that the second part will always have 2 digits?

Otherwise, 10161 could mean 1961-01-01, 1961-01-10 or 1961-10-01.

ballardw
Super User

What sort of file did you read to bring the data into SAS?

If that file was text and showed these dates as 010160 then you just need to use the proper format when reading the data to begin with.

 

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 4347 views
  • 0 likes
  • 5 in conversation