<?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: Using retain or lag in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571195#M161118</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I basically want to get the incidence density ratio (Incidence in observation with value =1 / incidence in observation with value=0) by each 'tc' .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to have an output with four incidence densities in the columns as IDR_DPD, IDR_DPY, IDR_AnginaPD, IDR_AginaPY.&lt;/P&gt;&lt;P&gt;I did this first code with a lag function to get the incidence density , IDR_DPD. And i can do that for the rest but i want to know how i can do this with a retain function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data one1;&lt;BR /&gt;set one;&lt;BR /&gt;by tc;&lt;BR /&gt;lag_I_dpd=lag(I_dpd);&lt;BR /&gt;IDR_DPD= I_dpd/lag_I_dpd;&lt;BR /&gt;run;&lt;BR /&gt;proc print; run;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Jul 2019 09:42:34 GMT</pubDate>
    <dc:creator>ChuksManuel</dc:creator>
    <dc:date>2019-07-04T09:42:34Z</dc:date>
    <item>
      <title>Using retain or lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571183#M161116</link>
      <description>&lt;P&gt;Hello programmers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to use the retain or lag function to help me calculate the Incidence density ratios.&lt;/P&gt;&lt;P&gt;My IDR= Incidence density for value=1/ incidence density for value=0 and i want to output only the last observations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please i'll be glad if anyone can give me an idea on how to go about this? I want to calculate the respective Incidence density for I_DPD, I2_DPY, I_AnginaPD and I2_AnginaPY.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input	tc	tn $	value	I_DPD	I2_DPY	I_AnginaPD	I2_AnginaPY;
datalines;
	1	Exhaustion	0	0.016	6.07	0.002	0.904
	1	Exhaustion	1	0.016	5.91	0.003	1.265
	2	Problemwalking	0	0.016	6.140	0.002	0.970
	2	Problemwalking	1	0.015	5.71	0.004	1.004
	3	ProblemStanding	0	0.016	6.17	0.008	0.95
	3	ProblemStanding	1	0.014	5.43	0.005	0.98
; run;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 09:17:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571183#M161116</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2019-07-04T09:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using retain or lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571184#M161117</link>
      <description>&lt;P&gt;So what does your desired result from this data look like?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 09:24:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571184#M161117</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-07-04T09:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using retain or lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571195#M161118</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I basically want to get the incidence density ratio (Incidence in observation with value =1 / incidence in observation with value=0) by each 'tc' .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to have an output with four incidence densities in the columns as IDR_DPD, IDR_DPY, IDR_AnginaPD, IDR_AginaPY.&lt;/P&gt;&lt;P&gt;I did this first code with a lag function to get the incidence density , IDR_DPD. And i can do that for the rest but i want to know how i can do this with a retain function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data one1;&lt;BR /&gt;set one;&lt;BR /&gt;by tc;&lt;BR /&gt;lag_I_dpd=lag(I_dpd);&lt;BR /&gt;IDR_DPD= I_dpd/lag_I_dpd;&lt;BR /&gt;run;&lt;BR /&gt;proc print; run;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 09:42:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571195#M161118</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2019-07-04T09:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using retain or lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571201#M161120</link>
      <description>&lt;P&gt;Don't&amp;nbsp;&lt;EM&gt;describe&lt;/EM&gt; the expected result,&amp;nbsp;&lt;EM&gt;show&lt;/EM&gt; it. As you can see, there seems to be some difficulty infering your requirements from the description alone.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 10:10:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571201#M161120</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-04T10:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using retain or lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571204#M161123</link>
      <description>&lt;P&gt;Thank you for the response.&lt;/P&gt;&lt;P&gt;Please final output would be something like this&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data finaloutput;
input	tc	tn $	value	I_DPD	I2_DPY	I_AnginaPD	I2_AnginaPY IDR_DPD IDR_DPY IDR_AnginaPD IDR_AnginaPY;
datalines;
	1	Exhaustion	1	0.016	5.91	0.003	1.265 . . . .
	2	Problemwalking	1	0.015	5.71	0.004	1.004 . . . .
	3	ProblemStanding	1	0.014	5.43	0.005	0.98 . . . .
; run;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30754i131CB63E32A9412E/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 10:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571204#M161123</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2019-07-04T10:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using retain or lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571208#M161126</link>
      <description>&lt;P&gt;So you just apply a where condition for value = 1 and add four variables that are always missing?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 10:31:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571208#M161126</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-04T10:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using retain or lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571241#M161139</link>
      <description>&lt;P&gt;If I am understanding this you just want to divide by the value of your measures on the non-ZERO rows with the value of the measure from the ZERO row.&lt;/P&gt;
&lt;P&gt;So if you have data like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
   input ID VALUE MEASURE ;
cards;
1 0 100
1 1 50
2 0 200
2 1 60
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You want to get a result that looks like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   input ID RATIO  ;
cards;
1 0.50 
2 0.30
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Only you have more than one analysis variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 14:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571241#M161139</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-04T14:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using retain or lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571283#M161149</link>
      <description>Rather than lag, why not do a merge?&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;merge one (where=value=0) &lt;BR /&gt;           one(where=value=1 rename = (I_DPD = I_DPD1 I2_DPY = I2_DPY1 ....));&lt;BR /&gt;&lt;BR /&gt;array  values0(*) I_dpd i2_dpy i_anginapd i2_anginapy;&lt;BR /&gt;array values1(*) .....;&lt;BR /&gt;array want(4) diff1-diff4;&lt;BR /&gt;do i=1 to 4;&lt;BR /&gt;want(i) = values1(i) / values0(i);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;At least that's one way, not quite dynamic. If you want a fully dynamic solution, it's likely worth transposing your data to a long format.</description>
      <pubDate>Thu, 04 Jul 2019 20:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571283#M161149</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-04T20:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Using retain or lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571299#M161156</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Don't&amp;nbsp;&lt;EM&gt;describe&lt;/EM&gt; the expected result,&amp;nbsp;&lt;EM&gt;show&lt;/EM&gt; it. As you can see, there seems to be some difficulty infering your requirements from the description alone.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;said.&amp;nbsp; I don't know what "incidence density" is.&amp;nbsp; I suppose I could Google it.&amp;nbsp; But I consider myself a good SAS programmer, so could probably help you if I knew what your target data was.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, provide data steps as "have" (your source data) and "want" (your target results).&amp;nbsp; They should be self-contained data steps using the datalines statement, entered using the "Insert SAS code" icon (so the code does not get reformatted).&amp;nbsp; The code should be something we can cut-and-paste from here into SAS and it runs without error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once we have that information, we can code a solution that matches your target data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise, if you &lt;U&gt;&lt;STRONG&gt;describe&lt;/STRONG&gt; &lt;/U&gt;your data, then we will &lt;U&gt;&lt;STRONG&gt;describe&lt;/STRONG&gt; &lt;/U&gt;the code you need to write.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S.: Click, read, and comprehend the last three links in Kurt's signature block.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2019 00:04:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571299#M161156</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-07-05T00:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using retain or lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571302#M161159</link>
      <description>&lt;P&gt;Hello Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's exactly what i want to do. To find the ratio between the lower and the upper.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2019 01:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-retain-or-lag/m-p/571302#M161159</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2019-07-05T01:17:48Z</dc:date>
    </item>
  </channel>
</rss>

