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

How do we convert date9 style character date,with missing day represented as 'UN' ,and missing month represented as 'UNK' into ISO8601 date?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

Tom_0-1653751669126.png

 

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star

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.

 

 

Tom
Super User Tom
Super User

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;

Tom_0-1653751669126.png

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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