<?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 increment a value in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/increment-a-value/m-p/531988#M5954</link>
    <description>&lt;P&gt;data test;&lt;BR /&gt;input ID $ typ $ sub $ ;&lt;BR /&gt;cards;&lt;BR /&gt;100 1 100&lt;BR /&gt;105 3 100&lt;/P&gt;&lt;P&gt;104 2 100&lt;/P&gt;&lt;P&gt;107 5 100&lt;/P&gt;&lt;P&gt;108 4 100&lt;BR /&gt;110 1 200&lt;BR /&gt;118 3 200&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;expected-&lt;/P&gt;&lt;P&gt;ID typ sub derived_val&lt;/P&gt;&lt;P&gt;100 1 100 1001&lt;BR /&gt;105 3 100 1003&lt;/P&gt;&lt;P&gt;104 2 100 1002&lt;/P&gt;&lt;P&gt;107 5 100 1004&lt;/P&gt;&lt;P&gt;108 4 100 1005&lt;/P&gt;&lt;P&gt;110 1 200 2001&lt;BR /&gt;118 3 200 2003&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;other than 1 and 2 , the other values need to be incremented by from 3.&lt;/P&gt;</description>
    <pubDate>Fri, 01 Feb 2019 13:59:43 GMT</pubDate>
    <dc:creator>APU_A0154665</dc:creator>
    <dc:date>2019-02-01T13:59:43Z</dc:date>
    <item>
      <title>increment a value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/increment-a-value/m-p/531988#M5954</link>
      <description>&lt;P&gt;data test;&lt;BR /&gt;input ID $ typ $ sub $ ;&lt;BR /&gt;cards;&lt;BR /&gt;100 1 100&lt;BR /&gt;105 3 100&lt;/P&gt;&lt;P&gt;104 2 100&lt;/P&gt;&lt;P&gt;107 5 100&lt;/P&gt;&lt;P&gt;108 4 100&lt;BR /&gt;110 1 200&lt;BR /&gt;118 3 200&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;expected-&lt;/P&gt;&lt;P&gt;ID typ sub derived_val&lt;/P&gt;&lt;P&gt;100 1 100 1001&lt;BR /&gt;105 3 100 1003&lt;/P&gt;&lt;P&gt;104 2 100 1002&lt;/P&gt;&lt;P&gt;107 5 100 1004&lt;/P&gt;&lt;P&gt;108 4 100 1005&lt;/P&gt;&lt;P&gt;110 1 200 2001&lt;BR /&gt;118 3 200 2003&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;other than 1 and 2 , the other values need to be incremented by from 3.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 13:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/increment-a-value/m-p/531988#M5954</guid>
      <dc:creator>APU_A0154665</dc:creator>
      <dc:date>2019-02-01T13:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: increment a value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/increment-a-value/m-p/531998#M5957</link>
      <description>Hi APU_A0154665,&lt;BR /&gt;&lt;BR /&gt;Can you provide more information on what you want the code to do? Specifically, how are you calculating derived_val.&lt;BR /&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:08:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/increment-a-value/m-p/531998#M5957</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2019-02-01T14:08:16Z</dc:date>
    </item>
    <item>
      <title>Re: increment a value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/increment-a-value/m-p/532001#M5958</link>
      <description>&lt;P&gt;Hey , my intention is to get the derived field incremented.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;example -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID typ sub derived_val&lt;/P&gt;&lt;P&gt;100 1 100 1001&lt;BR /&gt;105 3 100 1003&lt;/P&gt;&lt;P&gt;104 2 100 1002&lt;/P&gt;&lt;P&gt;107 5 100 1004&lt;/P&gt;&lt;P&gt;108 4 100 1005&lt;/P&gt;&lt;P&gt;110 1 200 2001&lt;BR /&gt;118 3 200 2003&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if the typ is 1 then the derived_val should be as cat(sub,1) and same for 2 too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when it's 3 then the derived_val should be 1003 and then again if it's 3 then again it should be incremented by 1 and so on. The possible range for the typ is between 1 to 5.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hope,it's pretty clear to you .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:16:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/increment-a-value/m-p/532001#M5958</guid>
      <dc:creator>APU_A0154665</dc:creator>
      <dc:date>2019-02-01T14:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: increment a value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/increment-a-value/m-p/532015#M5960</link>
      <description>Sorry - No it doesn't make sense to me.&lt;BR /&gt;&lt;BR /&gt;If you are incrementing typ when type is 3, 4 or 5. Then I would expect your output to look like this:&lt;BR /&gt;&lt;BR /&gt;ID typ sub derived_val&lt;BR /&gt;&lt;BR /&gt;100 1 100 1001&lt;BR /&gt;105 3 100 1003&lt;BR /&gt;104 2 100 1002&lt;BR /&gt;107 5 100 1005&lt;BR /&gt;108 4 100 1004&lt;BR /&gt;110 1 200 2001&lt;BR /&gt;118 3 200 2004&lt;BR /&gt;&lt;BR /&gt;Observation 2, is the 1st occurrence of Typ 3 so derived_val is cat(sub,typ). &lt;BR /&gt;Observation 7, is the 2nd occurrence of Typ 3 so derived_val is cat(sub,typ+1). &lt;BR /&gt;If there was another Typ 3 observation then derived_val would be cat(sub,typ+2) and so on.&lt;BR /&gt;&lt;BR /&gt;From the look of your example, I think you want to actually increment if type is 3, 4 or 5, plus you want to reset when the sub changes</description>
      <pubDate>Fri, 01 Feb 2019 14:43:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/increment-a-value/m-p/532015#M5960</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2019-02-01T14:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: increment a value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/increment-a-value/m-p/532025#M5963</link>
      <description>&lt;P&gt;I think this is what you are looking for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	input ID $ typ $ sub $ ;
	cards;
	100 1 100
	105 3 100
	104 2 100
	107 5 100
	108 4 100
	110 1 200
	118 3 200
	;
run;

proc sort 
	in=test out=srtd ;
	by sub ;
run ;

data output ;
	retain counter ;
	set srtd ;
	by sub ;
	if first.sub then counter=0 ;
	if typ in ("1","2") then
		derived_val=cat(trim(sub),typ) ;
	else do ;
		if counter=0 then counter=inputn(typ,"8.") ;
		derived_val=cat(trim(sub),left(putn(counter,"8."))) ;
		counter+1 ;
	end ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To understand this code, I suggest you check out &lt;A href="https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lrcon&amp;amp;docsetTarget=n138da4gme3zb7n1nifpfhqv7clq.htm&amp;amp;locale=en" target="_self"&gt;BY group processing&lt;/A&gt; (first.sub) and &lt;A href="https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=p0t2ac0tfzcgbjn112mu96hkgg9o.htm&amp;amp;locale=en" target="_self"&gt;retained values&lt;/A&gt; (counter) in the SAS documentation&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:57:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/increment-a-value/m-p/532025#M5963</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2019-02-01T14:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: increment a value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/increment-a-value/m-p/532038#M5965</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/112601"&gt;@APU_A0154665&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hey , my intention is to get the derived field incremented.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;example -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID typ sub derived_val&lt;/P&gt;
&lt;P&gt;100 1 100 1001&lt;BR /&gt;105 3 100 1003&lt;/P&gt;
&lt;P&gt;104 2 100 1002&lt;/P&gt;
&lt;P&gt;107&lt;FONT color="#ff0000"&gt; 5&lt;/FONT&gt; 100 100&lt;FONT color="#ff0000"&gt;4&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;108 &lt;FONT color="#ff0000"&gt;4&lt;/FONT&gt; 100 100&lt;FONT color="#ff0000"&gt;5&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;110 1 200 2001&lt;BR /&gt;118 3 200 2003&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if the typ is 1 then the derived_val should be as cat(sub,1) and same for 2 too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But when it's 3 then the derived_val should be 1003 and then again if it's 3 then again it should be incremented by 1 and so on. The possible range for the typ is between 1 to 5.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hope,it's pretty clear to you .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please examine the red highlighted values and explain how the derived value is assigned. It does not match your rule text.&lt;/P&gt;
&lt;P&gt;Also, are the values text or numeric?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 15:25:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/increment-a-value/m-p/532038#M5965</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-02-01T15:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: increment a value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/increment-a-value/m-p/532520#M6029</link>
      <description>&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 08:58:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/increment-a-value/m-p/532520#M6029</guid>
      <dc:creator>APU_A0154665</dc:creator>
      <dc:date>2019-02-04T08:58:19Z</dc:date>
    </item>
  </channel>
</rss>

