<?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: my phreg takes forever to run in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236592#M12536</link>
    <description>&lt;P&gt;&amp;nbsp;Don't panic. There is a good trick you can use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because you define your covariate inside phreg the algorithm it use will change to a slower algorithm were calculation speed is proportional to N^2. (N=number of events).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What you can do is to aggregate your data on &lt;EM&gt;riskset, &lt;/EM&gt;then you get a dataset with a timevariable that indicate the time of the riskset. then you can define your covariate in a dataset before using phreg. calculation time of Phreg will then only be proportional to N. It is not that simple, but you can use my macro &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/A-method-to-speed-up-PROC-PHREG-when-doing-a-Cox-regression/ta-p/223571" target="_self"&gt;Here: how to speed up phreg&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the macro your program will be much like this example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data simulation;
  do covariate1=0 to 1;
    do covariate2=0 to 1;
    do i=1 to 100;
	*the timevariables are created such that ties will happens often;
    t=floor(-1000*log(ranuni(-1))/exp(0.1*(covariate1=1)+0.2*(covariate2=1)))/10+0.1;
	*a censoring variable c;
    c=-100*log(ranuni(-1));
	*events happens if survival time are less than censoring time;
    event=(t&amp;lt;c);
    exit=min(t,c);
    entry=0;
    output;
  end;
  end;
  end;
  drop i t c;
run;
quit;

*Example , a timedependent effect;
proc phreg data=simulation nosummary;
  covariate1_1=(exit&amp;lt;=5)*covariate1;
  covariate1_2=(exit&amp;gt;5)*covariate1;
  model (entry exit)*event(0)= covariate1_1 covariate1_2;
run;

*equivalent to:;
%coxaggregate(data=simulation,output=dataout,entry=entry,exit=exit,event=event,covariate=covariate1);
data dataout;
  set dataout;
  more5=(time&amp;gt;5);
run;
proc phreg data=dataout nosummary;
  class covariate1 more5/param=glm ;
  model dummytime*dummytime(2)= covariate1*more5 ;
  hazardratio covariate1/ at( more5=all);
  strata time ;
  weight weight;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 26 Nov 2015 14:44:42 GMT</pubDate>
    <dc:creator>JacobSimonsen</dc:creator>
    <dc:date>2015-11-26T14:44:42Z</dc:date>
    <item>
      <title>my phreg takes forever to run</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236496#M12530</link>
      <description>&lt;P&gt;&lt;BR /&gt;proc phreg data = dm_mty nosummary;&lt;BR /&gt;class sex (ref='F') ageg(ref='&amp;lt;30') / param = ref;&lt;BR /&gt;model ft*dead(0) = sex ageg xcvd1;&lt;BR /&gt;if cvd1=1 &amp;amp; surv_cvd1 &amp;lt; ft then xcvd1=1; else xcvd1=0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran the same program by strata case_phin, without adjusting sex and age. it worked. but I select a subgroup data, no strata, but adjusting sex and age, it just run and run ... no stop.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need the results for tomorrow's presentation. now I am panic.... Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2015 20:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236496#M12530</guid>
      <dc:creator>nyu</dc:creator>
      <dc:date>2015-11-25T20:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: my phreg takes forever to run</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236498#M12531</link>
      <description>What version of SAS are you using? Consider applying the IF condition outside of the proc and then running the proc phreg.</description>
      <pubDate>Wed, 25 Nov 2015 21:11:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236498#M12531</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-11-25T21:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: my phreg takes forever to run</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236500#M12532</link>
      <description>&lt;P&gt;sas 9.2. The if statemetn is required for this model. the variable is time dependent. I have run this model with STRATA. It worked. it just continue running when strata is removed.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2015 21:32:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236500#M12532</guid>
      <dc:creator>nyu</dc:creator>
      <dc:date>2015-11-25T21:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: my phreg takes forever to run</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236511#M12534</link>
      <description>&lt;P&gt;If you can stratify then you can put the IF statement outside the PROC.&amp;nbsp; That is, essentially, what stratification does.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What exactly are you trying to do?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Nov 2015 00:24:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236511#M12534</guid>
      <dc:creator>plf515</dc:creator>
      <dc:date>2015-11-26T00:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: my phreg takes forever to run</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236592#M12536</link>
      <description>&lt;P&gt;&amp;nbsp;Don't panic. There is a good trick you can use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because you define your covariate inside phreg the algorithm it use will change to a slower algorithm were calculation speed is proportional to N^2. (N=number of events).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What you can do is to aggregate your data on &lt;EM&gt;riskset, &lt;/EM&gt;then you get a dataset with a timevariable that indicate the time of the riskset. then you can define your covariate in a dataset before using phreg. calculation time of Phreg will then only be proportional to N. It is not that simple, but you can use my macro &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/A-method-to-speed-up-PROC-PHREG-when-doing-a-Cox-regression/ta-p/223571" target="_self"&gt;Here: how to speed up phreg&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the macro your program will be much like this example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data simulation;
  do covariate1=0 to 1;
    do covariate2=0 to 1;
    do i=1 to 100;
	*the timevariables are created such that ties will happens often;
    t=floor(-1000*log(ranuni(-1))/exp(0.1*(covariate1=1)+0.2*(covariate2=1)))/10+0.1;
	*a censoring variable c;
    c=-100*log(ranuni(-1));
	*events happens if survival time are less than censoring time;
    event=(t&amp;lt;c);
    exit=min(t,c);
    entry=0;
    output;
  end;
  end;
  end;
  drop i t c;
run;
quit;

*Example , a timedependent effect;
proc phreg data=simulation nosummary;
  covariate1_1=(exit&amp;lt;=5)*covariate1;
  covariate1_2=(exit&amp;gt;5)*covariate1;
  model (entry exit)*event(0)= covariate1_1 covariate1_2;
run;

*equivalent to:;
%coxaggregate(data=simulation,output=dataout,entry=entry,exit=exit,event=event,covariate=covariate1);
data dataout;
  set dataout;
  more5=(time&amp;gt;5);
run;
proc phreg data=dataout nosummary;
  class covariate1 more5/param=glm ;
  model dummytime*dummytime(2)= covariate1*more5 ;
  hazardratio covariate1/ at( more5=all);
  strata time ;
  weight weight;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Nov 2015 14:44:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236592#M12536</guid>
      <dc:creator>JacobSimonsen</dc:creator>
      <dc:date>2015-11-26T14:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: my phreg takes forever to run</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236593#M12537</link>
      <description>You can not put the "IF" outside the PHREG. The problem is because that the condition is dependent on the underlying timeaxis. Putting it outside the proc will introduce future-dependent covariates in the model, which obviously gives wrong results.</description>
      <pubDate>Thu, 26 Nov 2015 14:51:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236593#M12537</guid>
      <dc:creator>JacobSimonsen</dc:creator>
      <dc:date>2015-11-26T14:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: my phreg takes forever to run</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236595#M12538</link>
      <description>I just noted that "weights" were not possible in SAS 9.2. You get the university edition for free, which has the most recent version of SAS/STAT.&lt;BR /&gt;Unfortunately, without weights it is not possible to reduce the calculation time to be linear with number of events in a Cox-regression with timedependent variables.&lt;BR /&gt;&lt;BR /&gt;It is correct that you can use STRATA on the timedependent variable, unless the timedependent variable is the variable of interest (you dont get estiamtes for variables in STRATA).</description>
      <pubDate>Thu, 26 Nov 2015 15:16:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236595#M12538</guid>
      <dc:creator>JacobSimonsen</dc:creator>
      <dc:date>2015-11-26T15:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: my phreg takes forever to run</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236613#M12539</link>
      <description>&lt;P&gt;Thank you. It is extremely helpful. I will figure out the maicro and let you know. &amp;nbsp;Thanks again for the timely response.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Nov 2015 16:16:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236613#M12539</guid>
      <dc:creator>nyu</dc:creator>
      <dc:date>2015-11-26T16:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: my phreg takes forever to run</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236707#M12541</link>
      <description>Actually, there is one more possibibility that may be even easier than using the macro i suggested above.&lt;BR /&gt;&lt;BR /&gt;because your time-dependent variable is piecewise constant, you can make your dataset such that you split observations at the time where the covariate change it values. That is, you should have a entry and a exit variable such such that that the total observation time is the same. be aware that person that has event should be censored at time of change of covariate and only have a eventtime on the original eventtime. Then you can use phreg with delayed entry:&lt;BR /&gt;&lt;BR /&gt;model (entry exit)*event(0)=covariates&lt;BR /&gt;&lt;BR /&gt;Then you avoid creating timedependent variables inside phreg.&lt;BR /&gt;&lt;BR /&gt;The method will be fast if you use the FAST-option :&lt;BR /&gt;PROC PHREG DATA=mydata FAST;&lt;BR /&gt;...&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;It was introduced in the latest release from august this year, but included in the university edition. Without the fast-option the method with delayed entry will not be faster than using timedependent variables.</description>
      <pubDate>Fri, 27 Nov 2015 08:17:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/my-phreg-takes-forever-to-run/m-p/236707#M12541</guid>
      <dc:creator>JacobSimonsen</dc:creator>
      <dc:date>2015-11-27T08:17:21Z</dc:date>
    </item>
  </channel>
</rss>

