<?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 show date as a blank based on condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/show-date-as-a-blank-based-on-condition/m-p/760788#M240612</link>
    <description>&lt;PRE&gt;data have;
date1='01jan2021'd;
date2='01jan2021'd;
date3='31mar2021'd;
format date1 date2 date3 date9.;
yr_date1 = put(date1,monyy7.);
yr_date2 = put(date2,monyy7.);
yr_date3 = put(date3,monyy7.);
if yr_date1 &amp;lt;&amp;gt;yr_date2 then date2 = .;
if yr_date1 &amp;lt;&amp;gt;yr_date3 then date3 = .;
run;&lt;/PRE&gt;
&lt;P&gt;I have 3 dates.&amp;nbsp; Using date1 as the base, If the month and year are a match in date1 and date2 I want to show date2.&amp;nbsp; Same for the relationship between date1 and date3.&amp;nbsp; The only way I knew to handle was to convert the dates to string (ie date1 put statement).&amp;nbsp; if yr_date1 &amp;lt;&amp;gt;yr_date2 then date2 = .; if yr_date1 &amp;lt;&amp;gt;yr_date3 then date3 = .;&amp;nbsp; In this case date1 and date3 are not a match so I want date3 to show a blank.&amp;nbsp; However a value still shows for date3.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Aug 2021 23:49:27 GMT</pubDate>
    <dc:creator>Q1983</dc:creator>
    <dc:date>2021-08-10T23:49:27Z</dc:date>
    <item>
      <title>show date as a blank based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/show-date-as-a-blank-based-on-condition/m-p/760788#M240612</link>
      <description>&lt;PRE&gt;data have;
date1='01jan2021'd;
date2='01jan2021'd;
date3='31mar2021'd;
format date1 date2 date3 date9.;
yr_date1 = put(date1,monyy7.);
yr_date2 = put(date2,monyy7.);
yr_date3 = put(date3,monyy7.);
if yr_date1 &amp;lt;&amp;gt;yr_date2 then date2 = .;
if yr_date1 &amp;lt;&amp;gt;yr_date3 then date3 = .;
run;&lt;/PRE&gt;
&lt;P&gt;I have 3 dates.&amp;nbsp; Using date1 as the base, If the month and year are a match in date1 and date2 I want to show date2.&amp;nbsp; Same for the relationship between date1 and date3.&amp;nbsp; The only way I knew to handle was to convert the dates to string (ie date1 put statement).&amp;nbsp; if yr_date1 &amp;lt;&amp;gt;yr_date2 then date2 = .; if yr_date1 &amp;lt;&amp;gt;yr_date3 then date3 = .;&amp;nbsp; In this case date1 and date3 are not a match so I want date3 to show a blank.&amp;nbsp; However a value still shows for date3.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 23:49:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/show-date-as-a-blank-based-on-condition/m-p/760788#M240612</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2021-08-10T23:49:27Z</dc:date>
    </item>
    <item>
      <title>Re: show date as a blank based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/show-date-as-a-blank-based-on-condition/m-p/760790#M240614</link>
      <description>&lt;P&gt;How about something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	date1='01jan2021'd;
	date2='01jan2021'd;
	date3='31mar2021'd;
	format date1 date2 date3 date9.;
run;

data	want;
	DROP	_:;
	set have;
	_Year_Mon1	=	(YEAR(date1) * 100) + MONTH(date1);
	_Year_Mon2	=	(YEAR(date2) * 100) + MONTH(date2);
	_Year_Mon3	=	(YEAR(date3) * 100) + MONTH(date3);

	IF	_Year_Mon2	^=	_Year_Mon1	THEN
		CALL	MISSING(Date2);

	IF	_Year_Mon3	^=	_Year_Mon1	THEN
		CALL	MISSING(Date3);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to do this with a larger dataset, there would probably need to be some adjustments, but the YEAR() and MONTH() functions should still do what you would need.&amp;nbsp; If there were more dates per record than 3, it might be worth converting the code to use an array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 00:31:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/show-date-as-a-blank-based-on-condition/m-p/760790#M240614</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-08-11T00:31:01Z</dc:date>
    </item>
  </channel>
</rss>

