<?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: Retain or Lag? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retain-or-Lag/m-p/567809#M159725</link>
    <description>&lt;P&gt;Here's a modification of my code. It's still not giving me any output that's meaningful.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data two;
 set one;
  by outcome;
 retain difference_AUC_model0;
 if first.modelstep then difference_AUC_model0 = AUC;
 else difference_AUC_model0 = difference_AUC_model0 - AUC;
 run;  
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 21 Jun 2019 00:32:05 GMT</pubDate>
    <dc:creator>ChuksManuel</dc:creator>
    <dc:date>2019-06-21T00:32:05Z</dc:date>
    <item>
      <title>Retain or Lag?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-or-Lag/m-p/567801#M159721</link>
      <description>&lt;P&gt;Hello guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 5 models 0, 1,2,3,4. My variables are&amp;nbsp; tool1, tool2, tool3, tool5, tool6, tool11, tool12 and AUC&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input modelstep TOOL1 TOOL2 TOOL3 TOOL5 TOOL6 TOOL11 TOOL12 AUC&amp;nbsp;
datalines;
0 -0.097544 0.38682 -0.057215 0.19231 0.013377 -0.35196 0.58613 0.69676&amp;nbsp;
1 -0.097379 0.3858 -0.057377 0.19214 0.013363 -0.35187 0.58526 0.69668&amp;nbsp;
2 -0.096809 0.38621 -0.057295 0.19177 0.013297 -0.35061 0.58444 0.69618&amp;nbsp;
3 -0.09729 0.38838 -0.057003 0.19405 0.013242 -0.34783 0.57736 0.69666&amp;nbsp;
4 -0.096492 0.3881 -0.054853 0.19513 0.013091 -0.33446 0.57587 0.6963&amp;nbsp;
; run;

Data two;
set one;
retain difference_from_model0;
if first.AUC then difference_from_model0=0;
if last.id then output;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;i basically want to write a code to find the difference in AUC between model 0 and the other models (model 1 to model 4). Simply put , model 0- model1 will be first observation. model 0 - model 2 will be second observation. model 0 - model 3 will be third observation etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want my final output to be something like this&lt;/P&gt;&lt;P&gt;modelstep TOOL1 TOOL2 TOOL3 TOOL5 TOOL6 TOOL11 TOOL12 AUC Difference_from_model0&lt;/P&gt;&lt;P&gt;1 -0.097379 0.3858 -0.057377 0.19214 0.013363 -0.35187 0.58526 0.69668 xxxx&lt;BR /&gt;2 -0.096809 0.38621 -0.057295 0.19177 0.013297 -0.35061 0.58444 0.69618 yyyy&lt;BR /&gt;3 -0.09729 0.38838 -0.057003 0.19405 0.013242 -0.34783 0.57736 0.69666 zzzz&lt;BR /&gt;4 -0.096492 0.3881 -0.054853 0.19513 0.013091 -0.33446 0.57587 0.6963 cccc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to use the retain function but have not been successful. My code is attached. Any help will be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 22:57:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-or-Lag/m-p/567801#M159721</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2019-06-20T22:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: Retain or Lag?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-or-Lag/m-p/567809#M159725</link>
      <description>&lt;P&gt;Here's a modification of my code. It's still not giving me any output that's meaningful.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data two;
 set one;
  by outcome;
 retain difference_AUC_model0;
 if first.modelstep then difference_AUC_model0 = AUC;
 else difference_AUC_model0 = difference_AUC_model0 - AUC;
 run;  
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Jun 2019 00:32:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-or-Lag/m-p/567809#M159725</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2019-06-21T00:32:05Z</dc:date>
    </item>
    <item>
      <title>Re: Retain or Lag?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-or-Lag/m-p/567812#M159727</link>
      <description>&lt;P&gt;It does not look like you have any BY groups in that data.&amp;nbsp; It is all one group with different values of MODELSTEP.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set one;
  retain AUC0;
  if modelstep=0 then AUC0 = AUC ;
  diff = AUC - AUC0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have multiple models (each of which can have one or more steps) then you could use BY processing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set one;
  by model;
  retain AUC0;
  if first.model then AUC0=.;
  if modelstep=0 then AUC0 = AUC ;
  diff = AUC - AUC0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Jun 2019 00:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-or-Lag/m-p/567812#M159727</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-21T00:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Retain or Lag?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-or-Lag/m-p/567814#M159728</link>
      <description>&lt;P&gt;Thank you Tom.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank was indeed helpful&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2019 01:00:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-or-Lag/m-p/567814#M159728</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2019-06-21T01:00:57Z</dc:date>
    </item>
  </channel>
</rss>

