- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How do we convert date9 style character date,with missing day represented as 'UN' ,and missing month represented as 'UNK' into ISO8601 date?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please show example values and expected results.
data have;
input string1 $9.;
cards;
23JAN2022
UNFEB2021
UNUNK2020
;
data want;
set have;
length string2 $8;
date = input(string1,??date9.);
if not missing(date) then string2=put(date,yymmddn8.);
else do;
if string1 =: 'UNUN' then string2=substr(string1,6);
else if string1 =: 'UN' then do;
date = input(substr(string1,3),monyy7.);
if not missing(date) then string2=put(date,yymmn6.);
end;
end;
format date yymmdd10.;
run;
proc print;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you don't know either the day or the month of a partial date - I'm assuming here you at least know the year - but you still want a "complete" inaccurate date then you have to have rules to handle it. BTW ISO8601 just uses partial character strings for incomplete dates but these are useless for programming purposes.
For example if day is unknown then you could assign it to 1, or 15 or 30. If month is unknown then you could make it JAN, JUL or DEC. What do you want to do here? Remember there is NO standard for deciding what to do with missing date components, only common practice and the examples I have given are some of those common practices.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please show example values and expected results.
data have;
input string1 $9.;
cards;
23JAN2022
UNFEB2021
UNUNK2020
;
data want;
set have;
length string2 $8;
date = input(string1,??date9.);
if not missing(date) then string2=put(date,yymmddn8.);
else do;
if string1 =: 'UNUN' then string2=substr(string1,6);
else if string1 =: 'UN' then do;
date = input(substr(string1,3),monyy7.);
if not missing(date) then string2=put(date,yymmn6.);
end;
end;
format date yymmdd10.;
run;
proc print;
run;