<?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: Optimisation request in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Optimisation-request/m-p/625648#M184416</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Thank you for this ingenious solution.&lt;BR /&gt;Could you give me more explanations to understand the working mechanism&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Feb 2020 18:21:34 GMT</pubDate>
    <dc:creator>mansour_ib_sas</dc:creator>
    <dc:date>2020-02-18T18:21:34Z</dc:date>
    <item>
      <title>Optimisation request</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimisation-request/m-p/625639#M184409</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I find for a way to remove the intermediate step that create concat variable&lt;/P&gt;&lt;P&gt;From the key (date&amp;amp;code), i increment my counter once the value num or val have changed.&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;this is my program:&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;data&lt;/SPAN&gt; test;
&lt;SPAN&gt;format&lt;/SPAN&gt; &lt;SPAN&gt;date&lt;/SPAN&gt; date9.;
&lt;SPAN&gt;input&lt;/SPAN&gt;  &lt;SPAN&gt;date&lt;/SPAN&gt; date9. code num val;
cards;
20dec2019 &lt;SPAN&gt;33&lt;/SPAN&gt; &lt;SPAN&gt;1&lt;/SPAN&gt; &lt;SPAN&gt;34000&lt;/SPAN&gt; 
20dec2019 &lt;SPAN&gt;33&lt;/SPAN&gt; &lt;SPAN&gt;1&lt;/SPAN&gt; &lt;SPAN&gt;34000&lt;/SPAN&gt;
20dec2019 &lt;SPAN&gt;33&lt;/SPAN&gt; &lt;SPAN&gt;2&lt;/SPAN&gt; &lt;SPAN&gt;34000&lt;/SPAN&gt;
24may2019 &lt;SPAN&gt;35&lt;/SPAN&gt; &lt;SPAN&gt;1&lt;/SPAN&gt; &lt;SPAN&gt;28000&lt;/SPAN&gt;
24may2019 &lt;SPAN&gt;35&lt;/SPAN&gt; &lt;SPAN&gt;1&lt;/SPAN&gt; &lt;SPAN&gt;28000&lt;/SPAN&gt;
24may2019 &lt;SPAN&gt;35&lt;/SPAN&gt; &lt;SPAN&gt;2&lt;/SPAN&gt; &lt;SPAN&gt;28000&lt;/SPAN&gt;
24may2019 &lt;SPAN&gt;35&lt;/SPAN&gt; &lt;SPAN&gt;1&lt;/SPAN&gt; &lt;SPAN&gt;30000&lt;/SPAN&gt;
; &lt;SPAN&gt;run&lt;/SPAN&gt;;
&amp;nbsp;
&lt;SPAN&gt;data&lt;/SPAN&gt; test1;
&lt;SPAN&gt;set&lt;/SPAN&gt; test;
conca=cats&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;date&lt;/SPAN&gt;,code&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
&lt;SPAN&gt;run&lt;/SPAN&gt;;
&amp;nbsp;
&lt;SPAN&gt;data&lt;/SPAN&gt; test1&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;drop&lt;/SPAN&gt;=_lag: conca&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
&lt;SPAN&gt;set&lt;/SPAN&gt; test1;
&lt;SPAN&gt;by&lt;/SPAN&gt; conca notsorted;
&lt;SPAN&gt;retain&lt;/SPAN&gt; Id;
_lagnum=&lt;SPAN&gt;lag&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;num&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
_lagval=&lt;SPAN&gt;lag&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;val&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
&lt;SPAN&gt;if&lt;/SPAN&gt; first.conca  &lt;SPAN&gt;then&lt;/SPAN&gt; &lt;SPAN&gt;do&lt;/SPAN&gt;; 
Id=&lt;SPAN&gt;1&lt;/SPAN&gt;;
_lagconca=.;
_lagnum=.;
_lagval=.
;
&lt;SPAN&gt;end&lt;/SPAN&gt;;
&lt;SPAN&gt;else&lt;/SPAN&gt; &lt;SPAN&gt;do&lt;/SPAN&gt;;
&lt;SPAN&gt;if&lt;/SPAN&gt; _lagnum ne num &lt;SPAN&gt;or&lt;/SPAN&gt; _lagval ne val &lt;SPAN&gt;then&lt;/SPAN&gt; Id+&lt;SPAN&gt;1&lt;/SPAN&gt;;&lt;SPAN&gt;end&lt;/SPAN&gt;;
&lt;SPAN&gt;run&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;P&gt;Thank you for your inswers;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 17:50:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimisation-request/m-p/625639#M184409</guid>
      <dc:creator>mansour_ib_sas</dc:creator>
      <dc:date>2020-02-18T17:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: Optimisation request</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimisation-request/m-p/625640#M184410</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
format date date9.;
input  date date9. code num val;
cards;
20dec2019 33 1 34000 
20dec2019 33 1 34000
20dec2019 33 2 34000
24may2019 35 1 28000
24may2019 35 1 28000
24may2019 35 2 28000
24may2019 35 1 30000
; run;

data want;
 set test;
 by date code num notsorted;
 if first.code then id=1;
 else if first.num then id+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Sorry if my understanding of the requirement is &lt;STRONG&gt;incorrect&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 17:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimisation-request/m-p/625640#M184410</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-18T17:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Optimisation request</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimisation-request/m-p/625642#M184411</link>
      <description>&lt;P&gt;I'm certainly not sure what the end results is going to be, as the ID variable does not get created in any specific way that I can identify, and I haven't tried to trace through your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nevertheless, to answer your specific question&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I find for a way to remove the intermediate step that create concat variable&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is how you do it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
format date date9.;
input  date date9. code num val;
conca=cats(date,code);
cards;
20dec2019 33 1 34000 
20dec2019 33 1 34000
20dec2019 33 2 34000
24may2019 35 1 28000
24may2019 35 1 28000
24may2019 35 2 28000
24may2019 35 1 30000
; run;
 
data test1(drop=_lag: conca);
set test;
by conca notsorted;
retain Id;
_lagnum=lag(num);
_lagval=lag(val);
if first.conca  then do; 
Id=1;
_lagconca=.;
_lagnum=.;
_lagval=.
;
end;
else do;
if _lagnum ne num or _lagval ne val then Id+1;end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course, concatenating the date (which is a number) with a code value (which is a number) isn't necessary if you want to do counting by date/code combination, you can use one of many SAS PROCs to do this counting, or by using DATA step features. I do not give an example as I'm still not sure what you are doing.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 18:02:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimisation-request/m-p/625642#M184411</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-18T18:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: Optimisation request</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimisation-request/m-p/625648#M184416</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thank you for this ingenious solution.&lt;BR /&gt;Could you give me more explanations to understand the working mechanism&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 18:21:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimisation-request/m-p/625648#M184416</guid>
      <dc:creator>mansour_ib_sas</dc:creator>
      <dc:date>2020-02-18T18:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: Optimisation request</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimisation-request/m-p/625650#M184417</link>
      <description>&lt;P&gt;Basically, Your concatenation gave me impression or rather idea that the BY GROUP hierarchy is Date code (parent group), num(child group or subgroup)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So with that idea, I assumed the only counter would have to be on the child group as the child can have only one (biological parents haha) whereas the parent's number of children may vary. So for every new num you increment the counter and reset the counter to 1 when the parent changes. Hope this analogy makes sense.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 18:28:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimisation-request/m-p/625650#M184417</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-18T18:28:03Z</dc:date>
    </item>
  </channel>
</rss>

