<?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: assign year and month for missing date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/assign-year-and-month-for-missing-date/m-p/701131#M25751</link>
    <description>&lt;P&gt;You have to specify dates in a specific format in SAS or use the MDY() function. Both types of date require a day component though you don't need to use it since the format will not display it so just set it to the 1st or 15th as you prefer.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To specify a date you need to use the DATE9 format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if newdate = . then newdate = "01Sep2020"d;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if newdate = . then newdate = mdy(9, 1, 2020);&lt;/PRE&gt;
&lt;P&gt;SAS stores dates and times as numbers so when you provide 202009 that's a number that represents a date, SAS does not interpret it September 2020.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a great, but longer and in depth, reference for dates and times in SAS&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&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/322157"&gt;@urban58&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello SAS community,&lt;/P&gt;
&lt;P&gt;I have the following&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;examdate&lt;/P&gt;
&lt;P&gt;08/25/2020&lt;/P&gt;
&lt;P&gt;09/01/2020&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;09/14/2020&lt;/P&gt;
&lt;P&gt;10/01/2020&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to extract year and month, if examdate is missing then year and month variable (newdate)=202009 so I get the following&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;examdate newdate&lt;/P&gt;
&lt;P&gt;08/25/2020 202008&lt;/P&gt;
&lt;P&gt;09/01/2020 202009&lt;/P&gt;
&lt;P&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 202009&lt;/P&gt;
&lt;P&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 202009&lt;/P&gt;
&lt;P&gt;09/14/2020 202009&lt;/P&gt;
&lt;P&gt;10/01/2020 202010&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;With the following code, I'm able to extract year and month correctly if examdate is NOT missing&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set have;&lt;BR /&gt;newdate = examdate;&lt;BR /&gt;if newdate = . then newdate = 202009;&lt;BR /&gt;FORMAT newdate yymmn6.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;if examdate is missing, I get the following&lt;/P&gt;
&lt;P&gt;examdate newdate&lt;/P&gt;
&lt;P&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;251301&lt;/P&gt;
&lt;P&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;251301&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help so I get 202009 instead of 251301.&lt;/P&gt;
&lt;P&gt;Thanks in advance,&lt;/P&gt;
&lt;P&gt;Margaret&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Nov 2020 02:52:44 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-11-24T02:52:44Z</dc:date>
    <item>
      <title>assign year and month for missing date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/assign-year-and-month-for-missing-date/m-p/701128#M25749</link>
      <description>&lt;P&gt;Hello SAS community,&lt;/P&gt;&lt;P&gt;I have the following&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;examdate&lt;/P&gt;&lt;P&gt;08/25/2020&lt;/P&gt;&lt;P&gt;09/01/2020&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;09/14/2020&lt;/P&gt;&lt;P&gt;10/01/2020&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to extract year and month, if examdate is missing then year and month variable (newdate)=202009 so I get the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;examdate newdate&lt;/P&gt;&lt;P&gt;08/25/2020 202008&lt;/P&gt;&lt;P&gt;09/01/2020 202009&lt;/P&gt;&lt;P&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 202009&lt;/P&gt;&lt;P&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 202009&lt;/P&gt;&lt;P&gt;09/14/2020 202009&lt;/P&gt;&lt;P&gt;10/01/2020 202010&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;With the following code, I'm able to extract year and month correctly if examdate is NOT missing&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set have;&lt;BR /&gt;newdate = examdate;&lt;BR /&gt;if newdate = . then newdate = 202009;&lt;BR /&gt;FORMAT newdate yymmn6.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;if examdate is missing, I get the following&lt;/P&gt;&lt;P&gt;examdate newdate&lt;/P&gt;&lt;P&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;251301&lt;/P&gt;&lt;P&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;251301&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help so I get 202009 instead of 251301.&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Margaret&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2020 02:34:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/assign-year-and-month-for-missing-date/m-p/701128#M25749</guid>
      <dc:creator>urban58</dc:creator>
      <dc:date>2020-11-24T02:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: assign year and month for missing date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/assign-year-and-month-for-missing-date/m-p/701131#M25751</link>
      <description>&lt;P&gt;You have to specify dates in a specific format in SAS or use the MDY() function. Both types of date require a day component though you don't need to use it since the format will not display it so just set it to the 1st or 15th as you prefer.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To specify a date you need to use the DATE9 format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if newdate = . then newdate = "01Sep2020"d;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if newdate = . then newdate = mdy(9, 1, 2020);&lt;/PRE&gt;
&lt;P&gt;SAS stores dates and times as numbers so when you provide 202009 that's a number that represents a date, SAS does not interpret it September 2020.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a great, but longer and in depth, reference for dates and times in SAS&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&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/322157"&gt;@urban58&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello SAS community,&lt;/P&gt;
&lt;P&gt;I have the following&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;examdate&lt;/P&gt;
&lt;P&gt;08/25/2020&lt;/P&gt;
&lt;P&gt;09/01/2020&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;09/14/2020&lt;/P&gt;
&lt;P&gt;10/01/2020&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to extract year and month, if examdate is missing then year and month variable (newdate)=202009 so I get the following&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;examdate newdate&lt;/P&gt;
&lt;P&gt;08/25/2020 202008&lt;/P&gt;
&lt;P&gt;09/01/2020 202009&lt;/P&gt;
&lt;P&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 202009&lt;/P&gt;
&lt;P&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 202009&lt;/P&gt;
&lt;P&gt;09/14/2020 202009&lt;/P&gt;
&lt;P&gt;10/01/2020 202010&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;With the following code, I'm able to extract year and month correctly if examdate is NOT missing&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set have;&lt;BR /&gt;newdate = examdate;&lt;BR /&gt;if newdate = . then newdate = 202009;&lt;BR /&gt;FORMAT newdate yymmn6.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;if examdate is missing, I get the following&lt;/P&gt;
&lt;P&gt;examdate newdate&lt;/P&gt;
&lt;P&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;251301&lt;/P&gt;
&lt;P&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;251301&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help so I get 202009 instead of 251301.&lt;/P&gt;
&lt;P&gt;Thanks in advance,&lt;/P&gt;
&lt;P&gt;Margaret&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2020 02:52:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/assign-year-and-month-for-missing-date/m-p/701131#M25751</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-11-24T02:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: assign year and month for missing date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/assign-year-and-month-for-missing-date/m-p/701220#M25755</link>
      <description>Thank you Reeza, that worked perfectly!</description>
      <pubDate>Tue, 24 Nov 2020 14:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/assign-year-and-month-for-missing-date/m-p/701220#M25755</guid>
      <dc:creator>urban58</dc:creator>
      <dc:date>2020-11-24T14:12:43Z</dc:date>
    </item>
  </channel>
</rss>

