<?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: Problem with SUBSTR date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776713#M247067</link>
    <description>&lt;P&gt;What didn't work, please provide the full log.&lt;BR /&gt;It is also helpful if you:&lt;/P&gt;
&lt;P&gt;Provide some sample data&lt;BR /&gt;Build up your functions/code little by little testing as you go. For example&amp;nbsp;if you want to do something like function1(function2(function3,1,3),"x")) then start with just function3 and get that working first before adding function2 and finally function1.&lt;/P&gt;</description>
    <pubDate>Wed, 27 Oct 2021 11:49:02 GMT</pubDate>
    <dc:creator>AMSAS</dc:creator>
    <dc:date>2021-10-27T11:49:02Z</dc:date>
    <item>
      <title>Problem with SUBSTR date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776708#M247062</link>
      <description>&lt;P&gt;I need to extract the date using a subtr from 2021-09-11 to 2021-09&lt;/P&gt;
&lt;PRE&gt;	
create table PolisyEnd as 
    select distinct       
    (t4.spr_NRB) as NRB
	,datepart(t1.PRP_END_DATE) as POLICY_VINTAGE format yymmdd10.,

&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Gieorgie_0-1635332945511.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65079iDFC757A5C72DC357/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Gieorgie_0-1635332945511.png" alt="Gieorgie_0-1635332945511.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;when im trying use substr&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;,input(substr(datepart(t1.PRP_END_DATE,1,4))||'-'||substr(datepart(t1.PRP_END_DATE,5,2))||'-'||substr(datepart(t1.PRP_END_DATE,7,2)),yymmdd10.) &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I got error &lt;/P&gt;
&lt;P&gt;"WARNING: Function DATEPART requires at most 1 argument(s). The extra one(s) will be ignored.&lt;BR /&gt;ERROR: Function SUBSTR requires at least 2 argument(s).&lt;BR /&gt;WARNING: Function DATEPART requires at most 1 argument(s). The extra one(s) will be ignored.&lt;BR /&gt;ERROR: Function SUBSTR requires at least 2 argument(s).&lt;BR /&gt;WARNING: Function DATEPART requires at most 1 argument(s). The extra one(s) will be ignored.&lt;BR /&gt;ERROR: Function SUBSTR requires at least 2 argument(s)."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there chance to repair ?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 11:18:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776708#M247062</guid>
      <dc:creator>Gieorgie</dc:creator>
      <dc:date>2021-10-27T11:18:54Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SUBSTR date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776710#M247064</link>
      <description>&lt;P&gt;Looks like you misplaced a few closing parentheses.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think this works&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;,input(substr(datepart(t1.PRP_END_DATE),1,4)||'-'||substr(datepart(t1.PRP_END_DATE),5,2)||'-'||substr(datepart(t1.PRP_END_DATE),7,2),yymmdd10.)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Oct 2021 11:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776710#M247064</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-10-27T11:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SUBSTR date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776712#M247066</link>
      <description>Its not helped same error shows</description>
      <pubDate>Wed, 27 Oct 2021 11:41:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776712#M247066</guid>
      <dc:creator>Gieorgie</dc:creator>
      <dc:date>2021-10-27T11:41:35Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SUBSTR date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776713#M247067</link>
      <description>&lt;P&gt;What didn't work, please provide the full log.&lt;BR /&gt;It is also helpful if you:&lt;/P&gt;
&lt;P&gt;Provide some sample data&lt;BR /&gt;Build up your functions/code little by little testing as you go. For example&amp;nbsp;if you want to do something like function1(function2(function3,1,3),"x")) then start with just function3 and get that working first before adding function2 and finally function1.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 11:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776713#M247067</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-10-27T11:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SUBSTR date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776714#M247068</link>
      <description>&lt;P&gt;Below syntax is working - right?&lt;/P&gt;
&lt;PRE&gt;datepart(t1.PRP_END_DATE) as POLICY_VINTAGE format yymmdd10.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so then&amp;nbsp;PRP_END_DATE is a SAS DateTime value stored in a numerical variable as the count of seconds since 1/1/1960. You certainly can't use a string function like substr() for such a value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What problem do you actually want to solve given that your initial syntax appears to work already?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 11:53:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776714#M247068</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-10-27T11:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SUBSTR date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776715#M247069</link>
      <description>&lt;P&gt;What are you attempting to do, because as I look at your code it doesn't make sense to take the &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0rttbu7w62xgzn1damccyuwpld8.htm" target="_self"&gt;datepart&lt;/A&gt; of a SAS Date/Time value and then split it into a string.&lt;BR /&gt;The datepart is just going to be the number of days since 01JAN1960, a meaningless number to us humans&lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 11:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776715#M247069</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-10-27T11:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SUBSTR date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776718#M247070</link>
      <description>I would like to cut a day from 2022-07-23, so that only the year and month 2022-07 remain. He then needs to count the number for each year and group one record for each month</description>
      <pubDate>Wed, 27 Oct 2021 12:04:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776718#M247070</guid>
      <dc:creator>Gieorgie</dc:creator>
      <dc:date>2021-10-27T12:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SUBSTR date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776720#M247071</link>
      <description>&lt;P&gt;When you look at your data then you see a date string - but that's just because the format you've chosen prints the internal SAS Date value in a human readable form.&lt;/P&gt;
&lt;P&gt;A SAS datetime value is the count of seconds since 1/1/1960, the datepart() function converts the value to a SAS date value which is the count of days since 1/1/1960.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is very important that you understand SAS Date and Datetime values and if you don't then read-up in the SAS docu.&lt;/P&gt;
&lt;P&gt;It's very beneficial to store and work with dates as SAS date and datetime values as compared to working with dates stored as text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&lt;EM&gt;needs to count the number for each year and group one record for each month&lt;/EM&gt;"&lt;/P&gt;
&lt;P&gt;I don't fully understand what you're trying to do but try to understand below code. That should you give all the pointers.&lt;/P&gt;
&lt;P&gt;If you want us to provide you "real" code then you need to provide representative sample data for us (in the form of a SAS data step creating such data) and then also show the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  format prp_end_date datetime21.;
  do i=-1000 to 0 by 1;
    prp_end_date=intnx('dtday',datetime(),i,'s');
    output;
  end;
run;

proc sql;
select
  intnx('month',datepart(PRP_END_DATE),0,'b') as date_first_of_month format yymon7.,
  count(i) as cnt_i
from have
group by date_first_of_month
;
quit;&lt;/CODE&gt;&lt;/PRE&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>Wed, 27 Oct 2021 12:25:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776720#M247071</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-10-27T12:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SUBSTR date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776723#M247073</link>
      <description>Thanks ! i resolved this i changed data to string  ,put(datepart(t1.PRP_END_DATE),yymmd7.) as POLICY_VINTAGE,</description>
      <pubDate>Wed, 27 Oct 2021 12:50:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776723#M247073</guid>
      <dc:creator>Gieorgie</dc:creator>
      <dc:date>2021-10-27T12:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SUBSTR date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776726#M247074</link>
      <description>&lt;P&gt;&lt;STRONG&gt;DO NOT DO THIS.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your new variable is still a date-related value, so store it as a date, as it enables you to use SAS tools for date handling (INTNX, INTCK, ...)&lt;/P&gt;
&lt;P&gt;Do this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intnx('month',datepart(t1.PRP_END_DATE),0,'b') format=yymmd7. as POLICY_VINTAGE,&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The INTNX aligns the date to the first of the month, which is standard when using dates for periods.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 12:56:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-SUBSTR-date/m-p/776726#M247074</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-27T12:56:04Z</dc:date>
    </item>
  </channel>
</rss>

