<?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: Need to specify a model step for a specified Area Under the Curve (AUC) using a lag function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-to-specify-a-model-step-for-a-specified-Area-Under-the/m-p/817921#M322842</link>
    <description>&lt;P&gt;Combine DO UNTIL() loops with BY processing instead of awkward LAG or DIF functions :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until(last.outcome);
    set help; by outcome;
    if auc &amp;lt; 0.01 then lastStep = modelstep;
    end;
do until(last.outcome);
    set help; by outcome;
    if modelstep = lastStep then output;
    end;
drop lastStep;
run;

proc print noobs data=want; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_0-1655145739562.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72242i310D828FF6EAB851/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PGStats_0-1655145739562.png" alt="PGStats_0-1655145739562.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;All auc &amp;lt; 0.01 and no auc &amp;lt; 0.01 cases will be handled appropriately, i.e. by returning the last model and no model, respectively.&lt;/P&gt;</description>
    <pubDate>Mon, 13 Jun 2022 18:49:07 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2022-06-13T18:49:07Z</dc:date>
    <item>
      <title>Need to specify a model step for a specified Area Under the Curve (AUC) using a lag function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-specify-a-model-step-for-a-specified-Area-Under-the/m-p/817662#M322746</link>
      <description>&lt;P&gt;I have a dataset that I need help with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data help;
input modelstep var1 $ var2 $ var3 $ var4 $ var5 $ outcome auc;
datalines;
0 v1 v2 v3 v4 v5 1 0.003
1 v1 v2 v3 '' v5 1 0.004
2 v1 v2 v3 '' '' 1 0.007
3 '' v2 v3 '' '' 1 0.01 
4 '' '' v3 '' '' 1 0.02
0 v1 v2 '' v4 v5 2 0.005
1 v1 '' '' v4 v5 2 0.006
2 v1 '' '' '' v5 2 0.02
3 v1 '' '' '' '' 2 0.03
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This dataset represents an iterative process of backward selection of model variables where&lt;BR /&gt;I am required to identify (for each outcome) the model step at which a specified number of variables yields&lt;BR /&gt;an AUC difference of 0.01, and then specify the previous model step variables as my model of choice. I want to do that using a lag function to get the table outlined below.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mock pic.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72157i393B462F27C614DF/image-size/large?v=v2&amp;amp;px=999" role="button" title="mock pic.PNG" alt="mock pic.PNG" /&gt;&lt;/span&gt;&lt;BR /&gt;Because every row represents a model step (that is a number of variables leading to the desired AUC difference,&lt;BR /&gt;I would like to specify the row just before the model leading to the AUC difference of 0.01 for each outcome.*/&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Any help with that, please?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jun 2022 13:13:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-specify-a-model-step-for-a-specified-Area-Under-the/m-p/817662#M322746</guid>
      <dc:creator>ugly_duck_ling</dc:creator>
      <dc:date>2022-06-12T13:13:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need to specify a model step for a specified Area Under the Curve (AUC) using a lag function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-specify-a-model-step-for-a-specified-Area-Under-the/m-p/817775#M322792</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data help;
input modelstep var1 $ var2 $ var3 $ var4 $ var5 $ outcome auc;
datalines;
0 v1 v2 v3 v4 v5 1 0.003
1 v1 v2 v3 . v5 1 0.004
2 v1 v2 v3 . . 1 0.007
3 . v2 v3 . . 1 0.01 
4 . . v3 . . 1 0.02
0 v1 v2 . v4 v5 2 0.005
1 v1 . . v4 v5 2 0.006
2 v1 . . . v5 2 0.02
3 v1 . . . . 2 0.03
;
run;

data want;
 set help;
 lag_auc1=lag(auc);  
 lag_auc2=lag2(auc); 
 lag_auc3=lag3(auc); 
 lag_auc4=lag4(auc); 

 dif_auc1=dif(auc);  
 dif_auc2=dif2(auc); 
 dif_auc3=dif3(auc); 
 dif_auc4=dif4(auc); 

 if outcome ne lag(outcome)  then call missing(lag_auc1,dif_auc1);
 if outcome ne lag2(outcome) then call missing(lag_auc2,dif_auc2);
 if outcome ne lag3(outcome) then call missing(lag_auc3,dif_auc3);
 if outcome ne lag4(outcome) then call missing(lag_auc4,dif_auc4);

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Jun 2022 13:01:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-specify-a-model-step-for-a-specified-Area-Under-the/m-p/817775#M322792</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-06-13T13:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: Need to specify a model step for a specified Area Under the Curve (AUC) using a lag function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-specify-a-model-step-for-a-specified-Area-Under-the/m-p/817790#M322798</link>
      <description>&lt;P&gt;Thank you so much for the feedback. I have one more question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I wanted to specify the model step before which a 'dif_auc' was equal to 0.01, how can I code for that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am guessing:&lt;/P&gt;&lt;P&gt;if dif_auc= 0.01 then modelstep= _N_-1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2022 13:57:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-specify-a-model-step-for-a-specified-Area-Under-the/m-p/817790#M322798</guid>
      <dc:creator>ugly_duck_ling</dc:creator>
      <dc:date>2022-06-13T13:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: Need to specify a model step for a specified Area Under the Curve (AUC) using a lag function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-specify-a-model-step-for-a-specified-Area-Under-the/m-p/817921#M322842</link>
      <description>&lt;P&gt;Combine DO UNTIL() loops with BY processing instead of awkward LAG or DIF functions :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until(last.outcome);
    set help; by outcome;
    if auc &amp;lt; 0.01 then lastStep = modelstep;
    end;
do until(last.outcome);
    set help; by outcome;
    if modelstep = lastStep then output;
    end;
drop lastStep;
run;

proc print noobs data=want; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_0-1655145739562.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72242i310D828FF6EAB851/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PGStats_0-1655145739562.png" alt="PGStats_0-1655145739562.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;All auc &amp;lt; 0.01 and no auc &amp;lt; 0.01 cases will be handled appropriately, i.e. by returning the last model and no model, respectively.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2022 18:49:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-specify-a-model-step-for-a-specified-Area-Under-the/m-p/817921#M322842</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-06-13T18:49:07Z</dc:date>
    </item>
    <item>
      <title>Re: Need to specify a model step for a specified Area Under the Curve (AUC) using a lag function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-specify-a-model-step-for-a-specified-Area-Under-the/m-p/818055#M322897</link>
      <description>&lt;P&gt;You want this ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data help;
input modelstep var1 $ var2 $ var3 $ var4 $ var5 $ outcome auc;
datalines;
0 v1 v2 v3 v4 v5 1 0.003
1 v1 v2 v3 . v5 1 0.004
2 v1 v2 v3 . . 1 0.007
3 . v2 v3 . . 1 0.01 
4 . . v3 . . 1 0.02
0 v1 v2 . v4 v5 2 0.005
1 v1 . . v4 v5 2 0.006
2 v1 . . . v5 2 0.02
3 v1 . . . . 2 0.03
;
run;

data want;
 set help;
 lag_auc1=lag(auc);  
 lag_auc2=lag2(auc); 
 lag_auc3=lag3(auc); 
 lag_auc4=lag4(auc); 

 dif_auc1=dif(auc);  
 dif_auc2=dif2(auc); 
 dif_auc3=dif3(auc); 
 dif_auc4=dif4(auc); 

 if outcome ne lag(outcome)  then call missing(lag_auc1,dif_auc1);
 if outcome ne lag2(outcome) then call missing(lag_auc2,dif_auc2);
 if outcome ne lag3(outcome) then call missing(lag_auc3,dif_auc3);
 if outcome ne lag4(outcome) then call missing(lag_auc4,dif_auc4);


lag_modelstep=lag(modelstep);
if round(dif_auc1,1e-6) ne 0.01 or  outcome ne lag(outcome) then call missing(lag_modelstep);

run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jun 2022 11:51:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-specify-a-model-step-for-a-specified-Area-Under-the/m-p/818055#M322897</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-06-14T11:51:07Z</dc:date>
    </item>
  </channel>
</rss>

