- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi All,
I have the following set of numeric dates which I need to convert into a date format
10164
10168
10169
10170
10171
DATE = Input( Put( MyDate, 8.), date9.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.