<?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 Converting numeric to SAS date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-SAS-date/m-p/685038#M24269</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need some help converting a numeric variable into a SAS date variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to get the last day of the month into a new variable. The original variable is "Date_Collect" which is a date variable, then I used the intnx function to grab the last day of the month. The step I am struggling with is converting the lastday variable into a SAS date variable instead of a numeric variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run this code,&amp;nbsp;&lt;CODE class=" language-sas"&gt;lastday_date&lt;/CODE&gt;&amp;nbsp;is entirely blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
lastday_num=intnx('month',Date_Collect,0,'E');
lastday_date=input(put(lastday_num,date8.),yymmdd8.);
  format lastday_date date8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 18 Sep 2020 17:11:41 GMT</pubDate>
    <dc:creator>marleeakerson</dc:creator>
    <dc:date>2020-09-18T17:11:41Z</dc:date>
    <item>
      <title>Converting numeric to SAS date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-SAS-date/m-p/685038#M24269</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need some help converting a numeric variable into a SAS date variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to get the last day of the month into a new variable. The original variable is "Date_Collect" which is a date variable, then I used the intnx function to grab the last day of the month. The step I am struggling with is converting the lastday variable into a SAS date variable instead of a numeric variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run this code,&amp;nbsp;&lt;CODE class=" language-sas"&gt;lastday_date&lt;/CODE&gt;&amp;nbsp;is entirely blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
lastday_num=intnx('month',Date_Collect,0,'E');
lastday_date=input(put(lastday_num,date8.),yymmdd8.);
  format lastday_date date8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Sep 2020 17:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-SAS-date/m-p/685038#M24269</guid>
      <dc:creator>marleeakerson</dc:creator>
      <dc:date>2020-09-18T17:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Converting numeric to SAS date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-SAS-date/m-p/685042#M24270</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281255"&gt;@marleeakerson&lt;/a&gt;&amp;nbsp; Is this what you're looking for? All you need is a format to display the numeric date as a date value. Here is an example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
    lastday_num = intnx('month', "09Sep2020"d, 0, 'E');
    lastday_date = lastday_num;
    format lastday_date date8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; So you should just be able to use this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    lastday_num = intnx('month', Date_Collect, 0, 'E');
    lastday_date = lastday_num;
    format lastday_date date8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Sep 2020 18:26:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-SAS-date/m-p/685042#M24270</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-09-18T18:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: Converting numeric to SAS date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-SAS-date/m-p/685046#M24271</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; I'm not clear on what you're trying to do. INTNX is moving a date forward or backward in time. A SAS date value is ALREADY a numeric value. It represents the number of days either before or after Jan 1, 1960 which is internally stored as 0. So Jan 2, 1960 is stored as 1; Jan 3, 1960 is stored as 2; Dec 31, 1959 is stored as -1, etc. A date like Nov 15, 2019 would be stored internally as the number 21868, because it is 21868 days after Jan 1, 1960. So if you use INTNX to MOVE to the date Nov 30, 2019, then the internally stored number for THAT moved value would be 21883.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Do you want to create a character version of your Date_Collect value? INTNX is already creating a numeric variable for you with the value you want. You can run this program to test:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testnx;
  infile datalines;
  input Date_Collect : mmddyy.;
  lastday_num=intnx('month',Date_Collect,0,'E');
  putlog '=== === === ===' _n_=  date_collect= date_collect= date9. ' === === === === ===';
  putlog '===&amp;gt; ' lastday_num= '(this is internally stored number)';
  putlog '===&amp;gt; ' lastday_num= mmddyy10. '(this is formatted value)';
  putlog '===&amp;gt; ' lastday_num= date9. '(this is alternative format)';
return;
datalines;
11/15/2019
03/21/2020
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When I run the above program, this is what I see in the LOG:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1600450226756.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49541i260DDE5402970D9B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1600450226756.png" alt="Cynthia_sas_0-1600450226756.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Can you clarify what it is you need to do???&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 17:30:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-SAS-date/m-p/685046#M24271</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-09-18T17:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: Converting numeric to SAS date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-SAS-date/m-p/685051#M24272</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281255"&gt;@marleeakerson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need some help converting a numeric variable into a SAS date variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to get the last day of the month into a new variable. The original variable is "Date_Collect" which is a date variable, then I used the intnx function to grab the last day of the month. The step I am struggling with is converting the lastday variable into a SAS date variable instead of a numeric variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run this code,&amp;nbsp;&lt;CODE class=" language-sas"&gt;lastday_date&lt;/CODE&gt;&amp;nbsp;is entirely blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
lastday_num=intnx('month',Date_Collect,0,'E');
lastday_date=input(put(lastday_num,date8.),yymmdd8.);
  format lastday_date date8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Besides NOT needing&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;lastday_date=input(put(lastday_num,date8.),yymmdd8.);&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;because lastday_date is a date value, you are making a value that cannot be read with yymmdd8. When put a date with date8. format then you get a value with a leading space that looks like " 01SEP20". YYMMDD8 expects numerals that represent year month and day, like 20200901 (for 01SEP2020).&lt;/P&gt;
&lt;P&gt;The leading space created by DATE8 means almost any informat would fail.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you find someone using code that has &lt;STRONG&gt;any&lt;/STRONG&gt; code that uses: input(put(variable,&amp;lt;some date format&amp;gt;), &amp;lt;some date informat&amp;gt;)&lt;/P&gt;
&lt;P&gt;then do NOT copy that. The variable is Already a date value and changes in appearance just require a Format assignment or the variable is not a date and will yield unexpected results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&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" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 17:50:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-SAS-date/m-p/685051#M24272</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-18T17:50:13Z</dc:date>
    </item>
  </channel>
</rss>

