Hi All,
I have the following set of numeric dates which I need to convert into a date format
DATE = Input( Put( MyDate, 8.), date9.
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 attemptedDATE = Input( Put( MyDate, 8.), date9.but have failed.
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 attemptedDATE = Input( Put( MyDate, 8.), date9.but have failed.
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?
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.
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.