<?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: Extract YYYYDD from DATETIME26.7 keep result as numberic in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Extract-YYYYDD-from-DATETIME26-7-keep-result-as-numberic/m-p/379321#M11552</link>
    <description>&lt;P&gt;I can't test this right now, but it looks like you're just taking the wrong pieces. &amp;nbsp;If DATE_OF_EXIT is character and the new variable can be character:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;CASE WHEN DATE_OF_EXIT ^= .&amp;nbsp; &amp;amp;&amp;nbsp; EXIT_NOTIFICATION_STATUS = "1"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;THEN CAT(substr(DATE_OF_EXIT,&lt;FONT color="#FF0000"&gt;6,4&lt;/FONT&gt;), substr(DATE_OF_EXIT,&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;,2))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ELSE . END&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Notice switching to SUBSTR for a character field. &amp;nbsp;For other possibilities (incoming string is numeric, or output should be numeric), other functions can handle that:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;input(results of CAT, 6.) to get a numeric output&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For a numeric input and numeric output:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;cats(year(datepart(DATE_OF_EXIT)), day(datepart(DATE_OF_EXIT)))&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Apply INPUT to the result of CATS to get the output variable as numeric.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jul 2017 10:25:08 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-07-26T10:25:08Z</dc:date>
    <item>
      <title>Extract YYYYDD from DATETIME26.7 keep result as numberic</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Extract-YYYYDD-from-DATETIME26-7-keep-result-as-numberic/m-p/379295#M11546</link>
      <description>&lt;P&gt;Hi, I have a DATETIME26.7 string and I need to get it into the format of YYYYDD (YearDay), obviously this is a pretty useless date function so I don't think anything like this exists out the box. It's not my decision to use this value and I don't know the reasoning why so please don't let it become a debate over that...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm doing this as an expression in DI Studio if that makes a difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My first idea was a substr to extract the year and the day and then catx them together but that doesn't work on numeric fields, I've tried substrn but I just get '0' no matter what I try, and catx still wouldn't work on numeric values anyway (although it claims it does).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So for an example:&lt;/P&gt;&lt;P&gt;Input: 19JUL2016:12:00:00.0000000&lt;/P&gt;&lt;P&gt;Output: 201619&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is going to also be part of a case when and I need to end up with it as a numeric value still. I think it might need the format changing to character and back again, but can this be done as part of my case when rather than through multiple extracts before/after.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is essentailly where I'm up to (which errors)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CASE WHEN DATE_OF_EXIT ^= .&amp;nbsp; &amp;amp;&amp;nbsp; EXIT_NOTIFICATION_STATUS = "1"&lt;BR /&gt;THEN CATX("",substrn(DATE_OF_EXIT,1,4),substrn(DATE_OF_EXIT,6,2))&lt;BR /&gt;ELSE . END&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This gives me:&lt;/P&gt;&lt;P&gt;"ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;ERROR: Character expression requires a character format."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help appreciated, thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 09:30:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Extract-YYYYDD-from-DATETIME26-7-keep-result-as-numberic/m-p/379295#M11546</guid>
      <dc:creator>MRDM</dc:creator>
      <dc:date>2017-07-26T09:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Extract YYYYDD from DATETIME26.7 keep result as numberic</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Extract-YYYYDD-from-DATETIME26-7-keep-result-as-numberic/m-p/379298#M11547</link>
      <description>&lt;P&gt;I think your over complicating it, simply:&lt;/P&gt;
&lt;PRE&gt;date=input(scan(in_date,1,":");
format date yymmn6.;&lt;/PRE&gt;
&lt;P&gt;If its a string (not seen a datetime that long, so not sure if its valid, if it is a numeric then:&lt;/P&gt;
&lt;PRE&gt;date=datepart(in_date);
format date yymmn6.;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Jul 2017 09:18:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Extract-YYYYDD-from-DATETIME26-7-keep-result-as-numberic/m-p/379298#M11547</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-07-26T09:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: Extract YYYYDD from DATETIME26.7 keep result as numberic</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Extract-YYYYDD-from-DATETIME26-7-keep-result-as-numberic/m-p/379302#M11548</link>
      <description>&lt;P&gt;Thanks, that will work for the YYYYMM format I also need (but was reasonably confident about, I'll give your methods ago now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My main issue is that I need YYYYDD, as in YearDay, which doesn't seem straight forward.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 09:28:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Extract-YYYYDD-from-DATETIME26-7-keep-result-as-numberic/m-p/379302#M11548</guid>
      <dc:creator>MRDM</dc:creator>
      <dc:date>2017-07-26T09:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: Extract YYYYDD from DATETIME26.7 keep result as numberic</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Extract-YYYYDD-from-DATETIME26-7-keep-result-as-numberic/m-p/379307#M11549</link>
      <description>&lt;P&gt;Yearday format is called Julian format:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000197940.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000197940.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000197945.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000197945.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 09:50:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Extract-YYYYDD-from-DATETIME26-7-keep-result-as-numberic/m-p/379307#M11549</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-07-26T09:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: Extract YYYYDD from DATETIME26.7 keep result as numberic</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Extract-YYYYDD-from-DATETIME26-7-keep-result-as-numberic/m-p/379313#M11550</link>
      <description>&lt;P&gt;Thanks, I hadn't seen that, unfortunately though it looks as if it does the day as a 1-365, I need the day as it appears in the month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So 26th July 2017 would give me 201726, rather than 2016207 which I think Julian would do.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems like a useless data value to me without the&amp;nbsp;month included, but you gotta do what you gotta do.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 10:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Extract-YYYYDD-from-DATETIME26-7-keep-result-as-numberic/m-p/379313#M11550</guid>
      <dc:creator>MRDM</dc:creator>
      <dc:date>2017-07-26T10:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: Extract YYYYDD from DATETIME26.7 keep result as numberic</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Extract-YYYYDD-from-DATETIME26-7-keep-result-as-numberic/m-p/379317#M11551</link>
      <description>&lt;P&gt;Then you would need to do that by hand, there is no format to cover such a thing (as it makes no sense - I can understand if you wanted year and day of study for instance, but not day of an non-specific human term such as month without descriptor). &amp;nbsp;E.g&lt;/P&gt;
&lt;PRE&gt;num=input(cats(put(year(datepart(date)),z4.),put(day(datepart(date)),z2.)),best.);
&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Jul 2017 10:17:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Extract-YYYYDD-from-DATETIME26-7-keep-result-as-numberic/m-p/379317#M11551</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-07-26T10:17:45Z</dc:date>
    </item>
    <item>
      <title>Re: Extract YYYYDD from DATETIME26.7 keep result as numberic</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Extract-YYYYDD-from-DATETIME26-7-keep-result-as-numberic/m-p/379321#M11552</link>
      <description>&lt;P&gt;I can't test this right now, but it looks like you're just taking the wrong pieces. &amp;nbsp;If DATE_OF_EXIT is character and the new variable can be character:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;CASE WHEN DATE_OF_EXIT ^= .&amp;nbsp; &amp;amp;&amp;nbsp; EXIT_NOTIFICATION_STATUS = "1"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;THEN CAT(substr(DATE_OF_EXIT,&lt;FONT color="#FF0000"&gt;6,4&lt;/FONT&gt;), substr(DATE_OF_EXIT,&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;,2))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ELSE . END&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Notice switching to SUBSTR for a character field. &amp;nbsp;For other possibilities (incoming string is numeric, or output should be numeric), other functions can handle that:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;input(results of CAT, 6.) to get a numeric output&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For a numeric input and numeric output:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;cats(year(datepart(DATE_OF_EXIT)), day(datepart(DATE_OF_EXIT)))&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Apply INPUT to the result of CATS to get the output variable as numeric.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 10:25:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Extract-YYYYDD-from-DATETIME26-7-keep-result-as-numberic/m-p/379321#M11552</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-26T10:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Extract YYYYDD from DATETIME26.7 keep result as numberic</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Extract-YYYYDD-from-DATETIME26-7-keep-result-as-numberic/m-p/379324#M11553</link>
      <description>&lt;P&gt;Great stuff thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;, it's now working, it's a numeric field so I went with the second one:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;thanks that works fine as well, I went with Astoundings option just because I understand the syntax better, rather than the best32. format and the zX that I'm not too sure about.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CASE WHEN DATE_OF_EXIT ^= .&amp;nbsp; &amp;amp;&amp;nbsp; EXIT_NOTIFICATION_STATUS = "1"&lt;BR /&gt;THEN &lt;STRONG&gt;input(cats(year(datepart(DATE_OF_EXIT)),day(datepart(DATE_OF_EXIT))),6.)&lt;/STRONG&gt;&lt;BR /&gt;ELSE . END&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you both for the assistance.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 12:37:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Extract-YYYYDD-from-DATETIME26-7-keep-result-as-numberic/m-p/379324#M11553</guid>
      <dc:creator>MRDM</dc:creator>
      <dc:date>2017-07-26T12:37:14Z</dc:date>
    </item>
  </channel>
</rss>

