<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to compare the period and merge the data between two datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924260#M363807</link>
    <description>&lt;P&gt;Based on your screenshots your variables dateStartRole and dateEndRole are of type numeric meaning that they can only store numbers. The format attached to it then determines how these numbers get displayed.&lt;/P&gt;
&lt;P&gt;Format yymmddD10. is SAS supplied and only returns dates but not N or C. These N or C are displaying Special Missings that likely got created when you read the external data from a text file into a SAS table (that's what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;already mentioned in his last post).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe easiest would be if you deal with these C and N in your text source already when you read it into SAS.&lt;/P&gt;
&lt;P&gt;Below one way how to do this.&lt;/P&gt;
&lt;P&gt;- C in source gets set to a SAS date value for 01 January 5999&lt;/P&gt;
&lt;P&gt;- Any source string that's in the format yyyymmdd and though a valid input for informat yymmdd8. will become a SAS date value (count of days since 1/1/1960)&lt;/P&gt;
&lt;P&gt;- Any other source string will become a missing (a normal one and not a special one).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  invalue read_date(upcase)
    'C'     = '01jan5999'd
    low-high=[yymmdd8.]
    other   =.
    ;
quit;

data experience;
  input PERSON $ COMPANY_ID START_DATE  :read_date8. END_DATE  :read_date8. ind $;
  format START_DATE END_DATE yymmddd10. ;
  cards;
A 101 20050101 20121231 YES
A 103 20070601 20241031 NO
B 109 20140503 C YES
B 110 20180820 20221225 YES
;
run;

data have;
  input PERSON $ COMPANY_ID  ANNOUNCE_DATE :yymmdd8.;
  format ANNOUNCE_DATE yymmddn8. ; /*The company publicly announces that the director is serving the company*/
  cards;
A 103 20071231
B 109 20151231
;
run;

proc sql;
/*  create table want2 as*/
  select l.*, r.ind
  from have l
  left join
  experience r
  on l.person=r.person 
    and l.company_id=r.company_id 
    and not missing(r.start_date)
    and l.announce_date between r.start_date and r.end_date
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your screenshots also indicate that the start date could be missing (source string N). Condition&amp;nbsp;&lt;CODE class=" language-sas"&gt;and not missing(r.start_date)&lt;/CODE&gt;&amp;nbsp;will exclude such rows.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 14 Apr 2024 06:50:52 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2024-04-14T06:50:52Z</dc:date>
    <item>
      <title>How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924219#M363791</link>
      <description>&lt;P&gt;I would like to check the independence of directors based on the work experience data of all directors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since this process involves comparison and merging of data during the working period of two data sets,&lt;/P&gt;
&lt;P&gt;I would like to ask the experts how to solve this problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data experience;
input PERSON $ 	COM_ID  START END IND $;
cards;
A	001 20050101	20121231	 YES
A	003 20070601	20241031	 NO
B	009 20140503	20220429	 YES
B	010 20180820	20221225	 YES
;
proc print;
run;

data have;
input PERSON $ 	COM_ID  ANN_DATE ;
cards;
A 003 20071231
B 009 20151231
;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The form of data I want to present is listed below.&lt;/P&gt;
&lt;P&gt;Thank you for your help.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input PERSON $ 	COM_ID  ANN_DATE IND $;
cards;
A 003 20071231 NO
B 009 20151231 YES
;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Apr 2024 02:53:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924219#M363791</guid>
      <dc:creator>shawnchen0321</dc:creator>
      <dc:date>2024-04-13T02:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924220#M363792</link>
      <description>&lt;P&gt;Please explain what your variables represent. And explain the rules you used to decide that is the correct output for that input.&amp;nbsp; Once you know the rules you can begin trying to write a program to implement them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general if you want to compare dates it works much better when you have actual dates. Are your date values actual dates? Or just the strange integers in YYY,YM,MDD style that your data steps will create?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Apr 2024 03:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924220#M363792</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-13T03:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924221#M363793</link>
      <description>Understood, I will add and adjust it immediately.</description>
      <pubDate>Sat, 13 Apr 2024 04:03:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924221#M363793</guid>
      <dc:creator>shawnchen0321</dc:creator>
      <dc:date>2024-04-13T04:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924223#M363794</link>
      <description>&lt;P&gt;Hi expert,&lt;/P&gt;
&lt;P&gt;I would like to use existing experience data and identify whether the director is working in the company and whether he is independent.&lt;/P&gt;
&lt;P&gt;Those numbers are dates, so I changed the format of the template.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data experience;
input PERSON $ COMPANY_ID  START_DATE  END_DATE IND $;
format START_DATE yymmddn8. ;  /*The date on which the director started working for the company*/
format END_DATE yymmddn8. ; /*The date on which the director ended working for the company*/
cards;
A	101 20050101  20121231  YES
A	103 20070601  20241031  NO
B	109 20140503  20220429  YES
B 110 20180820  20221225  YES
;
run;

data have;
input PERSON $ COMPANY_ID  ANNOUNCE_DATE ;
format ANNOUNCE_DATE yymmddn8. ; /*The company publicly announces that the director is serving the company*/
cards;
A 103 20071231
B 109 20151231
;
run;
&lt;BR /&gt;
data want;
input PERSON $ COMPANY_ID  ANNOUNCE_DATE IND $;
format ANNOUNCE_DATE yymmddn8. ;
cards;
A 103 20071231 NO
B 109 20151231 YES
;
run;&lt;BR /&gt;/*If the date announced by the company is between the start and end dates of work experience, &lt;BR /&gt;the director’s independence can be identified*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Apr 2024 04:53:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924223#M363794</guid>
      <dc:creator>shawnchen0321</dc:creator>
      <dc:date>2024-04-13T04:53:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924224#M363795</link>
      <description>&lt;P&gt;For reading a date string into a numerical SAS variable holding a SAS Date value you need to instruct SAS via a informat how to read the string (so it becomes the count of days since 1/1/1960). Only then will a date format display the correct date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below returns what you've asked for.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data experience;
  input PERSON $ COMPANY_ID  (START_DATE  END_DATE) (:yymmdd8.) ind $;
  format START_DATE END_DATE yymmddn8. ;
  cards;
A 101 20050101 20121231 YES
A 103 20070601 20241031 NO
B 109 20140503 20220429 YES
B 110 20180820 20221225 YES
;
run;

data have;
  input PERSON $ COMPANY_ID  ANNOUNCE_DATE :yymmdd8.;
  format ANNOUNCE_DATE yymmddn8. ; /*The company publicly announces that the director is serving the company*/
  cards;
A 103 20071231
B 109 20151231
;
run;

data want;
  input PERSON $ COMPANY_ID  ANNOUNCE_DATE IND $;
  format ANNOUNCE_DATE yymmddn8.;
  cards;
A 103 20071231 NO
B 109 20151231 YES
;

proc sql;
/*  create table want2 as*/
  select l.*, r.ind
  from have l
  left join
  experience r
  on l.person=r.person 
    and l.company_id=r.company_id 
    and l.announce_date between r.start_date and r.end_date
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Apr 2024 05:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924224#M363795</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-04-13T05:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924225#M363796</link>
      <description>It worked, thank you.</description>
      <pubDate>Sat, 13 Apr 2024 05:52:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924225#M363796</guid>
      <dc:creator>shawnchen0321</dc:creator>
      <dc:date>2024-04-13T05:52:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924233#M363798</link>
      <description>&lt;P&gt;Sorry to bother you again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the data I downloaded, if the directors have been in the current company up to now, the date column shows C representing "current".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data experience;
  input PERSON $ COMPANY_ID  (START_DATE  END_DATE) (:yymmdd8.) ind $;
  format START_DATE END_DATE yymmddn8. ;
  cards;
A 101 20050101 20121231 YES
A 103 20070601 20241031 NO
B 109 20140503 C YES
B 110 20180820 20221225 YES
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-04-13 160029.png" style="width: 95px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95520iBB2E0D2415C2DEB4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-04-13 160029.png" alt="Screenshot 2024-04-13 160029.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This causes the following syntax to fail to execute.&lt;/P&gt;
&lt;P&gt;Do you know of any solution?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;l.announce_date between r.start_date and r.end_date&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Apr 2024 08:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924233#M363798</guid>
      <dc:creator>shawnchen0321</dc:creator>
      <dc:date>2024-04-13T08:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924243#M363801</link>
      <description>&lt;P&gt;Just change the condition to account for this new criteria.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;l.announce_date ge r.start_date
 and (missing(l.announce_date) or l.announce_date le r.end_date)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 13 Apr 2024 11:53:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924243#M363801</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-13T11:53:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924252#M363804</link>
      <description>&lt;P&gt;Just amend the selection criteria. Because we read this column with informat yymmdd10. a source character C will result in a missing value in target variable end_date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
/*  create table want2 as*/
  select l.*, r.ind
  from have l
  left join
  experience r
  on l.person=r.person 
    and l.company_id=r.company_id 
/*    and l.announce_date between r.start_date and r.end_date*/
    and l.announce_date &amp;gt;= r.start_date and ( l.announce_date &amp;lt;=r.end_date or missing(r.end_date) )
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;An alternative approach would be to not change the SQL selection but how you create your source table. If the source for end_date is C then set the date to something far in the future.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data experience;
  input PERSON $ COMPANY_ID  START_DATE :yymmdd8.  c_END_DATE :$upcase8. ind $;
  if c_END_DATE='C' then end_date='01jan5999'd;
  else end_date=input(c_END_DATE,yymmdd8.);
  format START_DATE END_DATE yymmddn8. ;
  drop c_END_DATE;
  cards;
A 101 20050101 20121231 YES
A 103 20070601 20241031 NO
B 109 20140503 C YES
B 110 20180820 20221225 YES
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;...or here another way how to read such data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  invalue end_date(upcase)
    'C' = '01jan5999'd
    other=[yymmdd8.]
    ;
quit;

data experience;
  input PERSON $ COMPANY_ID START_DATE  :yymmdd8. END_DATE  :end_date. ind $;
  format START_DATE END_DATE yymmddn8. ;
  cards;
A 101 20050101 20121231 YES
A 103 20070601 20241031 NO
B 109 20140503 C YES
B 110 20180820 20221225 YES
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Apr 2024 00:06:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924252#M363804</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-04-14T00:06:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924256#M363805</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Just amend the selection criteria. Because we read this column with informat yymmdd10. a source character C will result in a missing value in target variable end_date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That depend on whether you included the letter C in your MISSING statement or not.&amp;nbsp; If you have then the string 'C' will be converted to the special missing value .C instead of the regular missing value.&lt;/P&gt;
&lt;PRE&gt;1    missing ;
2    data test1;
3      input end_date :yymmdd. ;
4      format end_date yymmdd10.;
5      put end_date= ;
6    cards;

end_date=2024-04-12
NOTE: Invalid data for end_date in line 8 1-1.
end_date=.
RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
8          A
end_date=. _ERROR_=1 _N_=2
NOTE: Invalid data for end_date in line 9 1-1.
end_date=.
9          B
end_date=. _ERROR_=1 _N_=3
NOTE: Invalid data for end_date in line 10 1-1.
end_date=.
10         C
end_date=. _ERROR_=1 _N_=4
NOTE: The data set WORK.TEST1 has 4 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


11   ;
12
13   missing ABC;
14   data test2;
15     input end_date :yymmdd. ;
16     format end_date yymmdd10.;
17     put end_date= ;
18   cards;

end_date=2024-04-12
end_date=A
end_date=B
end_date=C
NOTE: The data set WORK.TEST2 has 4 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


23   ;
&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Apr 2024 03:18:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924256#M363805</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-14T03:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924259#M363806</link>
      <description>&lt;P style="margin-top: 0cm; background: white;"&gt;&lt;SPAN&gt;First, I would like to thank the two experts (@Patrick&amp;nbsp;and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;) for your assistance. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="background: white;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="background: white;"&gt;&lt;SPAN&gt;I have a question that I would like to ask you further. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="background: white;"&gt;&lt;SPAN&gt;The director's start and end information I obtained from the database shows:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="background: white;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="background: white;"&gt;&lt;SPAN&gt;C = Current&lt;/SPAN&gt;: &lt;SPAN&gt;C means that the director is still in office until now (which is informative). Although it is displayed in text, the format is still a date (as shown in the picture).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin-top: 0cm; background: white;"&gt;&lt;SPAN&gt;N = n/a: N means missing values ​​(which have no informational meaning).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin-top: 0cm; background: white;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin-top: 0cm; background: white;"&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="001.png" style="width: 523px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95526iF3F7C8272FA70C36/image-size/large?v=v2&amp;amp;px=999" role="button" title="001.png" alt="001.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="002.png" style="width: 534px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95527iC4A871307FFE0F6B/image-size/large?v=v2&amp;amp;px=999" role="button" title="002.png" alt="002.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin-top: 0cm; background: white;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="background: white;"&gt;&lt;SPAN&gt;I think a more appropriate way is to turn C into a date today or a long time in the future, &lt;/SPAN&gt;&lt;SPAN&gt;and treat N as a missing processing method.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin-top: 0cm; background: white;"&gt;&lt;SPAN&gt;Do you know how to adjust the program? Thanks again.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Apr 2024 04:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924259#M363806</guid>
      <dc:creator>shawnchen0321</dc:creator>
      <dc:date>2024-04-14T04:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924260#M363807</link>
      <description>&lt;P&gt;Based on your screenshots your variables dateStartRole and dateEndRole are of type numeric meaning that they can only store numbers. The format attached to it then determines how these numbers get displayed.&lt;/P&gt;
&lt;P&gt;Format yymmddD10. is SAS supplied and only returns dates but not N or C. These N or C are displaying Special Missings that likely got created when you read the external data from a text file into a SAS table (that's what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;already mentioned in his last post).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe easiest would be if you deal with these C and N in your text source already when you read it into SAS.&lt;/P&gt;
&lt;P&gt;Below one way how to do this.&lt;/P&gt;
&lt;P&gt;- C in source gets set to a SAS date value for 01 January 5999&lt;/P&gt;
&lt;P&gt;- Any source string that's in the format yyyymmdd and though a valid input for informat yymmdd8. will become a SAS date value (count of days since 1/1/1960)&lt;/P&gt;
&lt;P&gt;- Any other source string will become a missing (a normal one and not a special one).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  invalue read_date(upcase)
    'C'     = '01jan5999'd
    low-high=[yymmdd8.]
    other   =.
    ;
quit;

data experience;
  input PERSON $ COMPANY_ID START_DATE  :read_date8. END_DATE  :read_date8. ind $;
  format START_DATE END_DATE yymmddd10. ;
  cards;
A 101 20050101 20121231 YES
A 103 20070601 20241031 NO
B 109 20140503 C YES
B 110 20180820 20221225 YES
;
run;

data have;
  input PERSON $ COMPANY_ID  ANNOUNCE_DATE :yymmdd8.;
  format ANNOUNCE_DATE yymmddn8. ; /*The company publicly announces that the director is serving the company*/
  cards;
A 103 20071231
B 109 20151231
;
run;

proc sql;
/*  create table want2 as*/
  select l.*, r.ind
  from have l
  left join
  experience r
  on l.person=r.person 
    and l.company_id=r.company_id 
    and not missing(r.start_date)
    and l.announce_date between r.start_date and r.end_date
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your screenshots also indicate that the start date could be missing (source string N). Condition&amp;nbsp;&lt;CODE class=" language-sas"&gt;and not missing(r.start_date)&lt;/CODE&gt;&amp;nbsp;will exclude such rows.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Apr 2024 06:50:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924260#M363807</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-04-14T06:50:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924264#M363808</link>
      <description>&lt;P&gt;Big thanks to the two experts &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I may not be completely clear about the format of SAS,&lt;/P&gt;
&lt;P&gt;but I generally understand that what the experts mean is to create a new format, and then apply this format when the data is newly created,&lt;/P&gt;
&lt;P&gt;so that C becomes a future date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, my dataset is downloaded from the database and imported into SAS in the sas7bdat file format.&lt;/P&gt;
&lt;P&gt;I have just tried for a long time and it seems that there is no way to convert C into a future date.&lt;/P&gt;
&lt;P&gt;Maybe I'll just use missing to handle it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="003.png" style="width: 594px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95531i9769D0146543C81B/image-size/large?v=v2&amp;amp;px=999" role="button" title="003.png" alt="003.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="004.png" style="width: 357px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95532i942CCA04C8879D31/image-size/large?v=v2&amp;amp;px=999" role="button" title="004.png" alt="004.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I feel like two experts did their best, thank you very much anyway.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Apr 2024 08:39:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924264#M363808</guid>
      <dc:creator>shawnchen0321</dc:creator>
      <dc:date>2024-04-14T08:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924269#M363809</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/420121"&gt;@shawnchen0321&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/420121"&gt;@shawnchen0321&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="003.png" style="width: 594px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95531i9769D0146543C81B/image-size/large?v=v2&amp;amp;px=999" role="button" title="003.png" alt="003.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="004.png" style="width: 357px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95532i942CCA04C8879D31/image-size/large?v=v2&amp;amp;px=999" role="button" title="004.png" alt="004.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You are lucky that you start already with a SAS dataset (i.e., a .sas7bdat file). Then you don't need the READ_DATE. informat to create variable DATEENDROLE2:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data employ_c;
set employ;
if DATEENDROLE=&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;.C&lt;/STRONG&gt;&lt;/FONT&gt; then DATEENDROLE2='01jan5999'd;
else DATEENDROLE2=DATEENDROLE;
&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;format DATEENDROLE2 yymmdd10.;&lt;/STRONG&gt;&lt;/FONT&gt;
keep DATESTARTROLE DATEENDROLE:;
run;&lt;/PRE&gt;
&lt;P&gt;As has been pointed out earlier, DATEENDROLE is a &lt;EM&gt;numeric&lt;/EM&gt; variable and those Cs and Ns are &lt;EM&gt;special missing values&lt;/EM&gt;, which must be referred to as &lt;FONT face="courier new,courier"&gt;.C&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;.N&amp;nbsp;&lt;/FONT&gt;(or &lt;FONT face="courier new,courier"&gt;.c&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;.n&lt;/FONT&gt;), respectively, in SAS code such as your IF-THEN statement to distinguish them from &lt;EM&gt;character strings&lt;/EM&gt; like &lt;FONT face="courier new,courier"&gt;"C"&lt;/FONT&gt;&amp;nbsp;or&amp;nbsp;&lt;FONT face="courier new,courier"&gt;'N'&lt;/FONT&gt; and &lt;EM&gt;variable names&lt;/EM&gt; like &lt;FONT face="courier new,courier"&gt;C&lt;/FONT&gt;&amp;nbsp;or &lt;FONT face="courier new,courier"&gt;N&lt;/FONT&gt;. I have also added a FORMAT statement to make the newly created values human readable as dates. (Note that even an unconditional assignment&amp;nbsp;DATEENDROLE2=DATEENDROLE would not transfer the format of DATEENDROLE to DATEENDROLE2.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Apr 2024 10:59:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924269#M363809</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-04-14T10:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924270#M363810</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;It worked, thank you.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I learned a lot from you, &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;thank you experts&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Apr 2024 11:17:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924270#M363810</guid>
      <dc:creator>shawnchen0321</dc:creator>
      <dc:date>2024-04-14T11:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924276#M363812</link>
      <description>&lt;P&gt;From that PHOTOGRAPH of your VIEWTABLE screen it looks you already have DATE variables. But that some of the values have the special missing value of .N and others have the special missing value of .C.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to convert .C to some other date (why???) then a simple IF/THEN should do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if dateendrole=.c then dateendrole='31DEC2099'd ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Apr 2024 15:13:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924276#M363812</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-14T15:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924278#M363814</link>
      <description>&lt;P&gt;If the variable is numeric and displays as N or C then value is .n or .c.&amp;nbsp; SAS has 28 missing values.&amp;nbsp; The regular value is referenced in code as . (and normally prints as . also).&amp;nbsp; The others are referenced by period followed a letter or an underscore.&amp;nbsp; All of them are treated as missing so there should not be any need to convert .N into .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you want to convert .C into some other value?&lt;/P&gt;</description>
      <pubDate>Sun, 14 Apr 2024 15:24:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924278#M363814</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-14T15:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924310#M363823</link>
      <description>&lt;P&gt;Hello expert &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I need to identify the company announcement date that falls between the start and end dates of the director’s employment, &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;but the end date may display C and N at the same time (as&amp;nbsp;shown in the previous picture).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my dataset, it shows:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;C = Current&lt;/SPAN&gt;:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;C means that the director is still in office until now (which is informative).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;N = n/a: N means missing values ​​(which have no informational meaning).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If the program is used to allow missing, it may be inappropriate.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thus, I think a more appropriate way is to turn C into a long time in the future&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;and treat N as a missing processing method.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much for your comment to make the program more perfect.&amp;nbsp;Respect!&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 04:42:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924310#M363823</guid>
      <dc:creator>shawnchen0321</dc:creator>
      <dc:date>2024-04-15T04:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924311#M363824</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/420121"&gt;@shawnchen0321&lt;/a&gt;&amp;nbsp;Read through the answers already provided. The code for converting a special missing .C to a date in the future has already been shared here.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 04:44:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924311#M363824</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-04-15T04:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare the period and merge the data between two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924312#M363825</link>
      <description>&lt;P&gt;Hello experts &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have solved the problem, and the program works successfully.&lt;/P&gt;
&lt;P&gt;Thank you again.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 04:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-the-period-and-merge-the-data-between-two/m-p/924312#M363825</guid>
      <dc:creator>shawnchen0321</dc:creator>
      <dc:date>2024-04-15T04:49:31Z</dc:date>
    </item>
  </channel>
</rss>

