<?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: Calling PROC PHREG multiple times in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Calling-PROC-PHREG-multiple-times/m-p/686536#M33060</link>
    <description>&lt;P&gt;Thank you for the reply. Actually, the manual coding of the variable needs to be inside the proc phreg. Otherwise, the results are not the same.&lt;/P&gt;</description>
    <pubDate>Thu, 24 Sep 2020 21:26:51 GMT</pubDate>
    <dc:creator>themanoj20080</dc:creator>
    <dc:date>2020-09-24T21:26:51Z</dc:date>
    <item>
      <title>Calling PROC PHREG multiple times</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Calling-PROC-PHREG-multiple-times/m-p/686514#M33058</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I am trying to use phreg procedure and extract the likelihood value. I can do this for one value of c however I need to repeat this for c=1,...,50. For each value of c, I need to store the likelihood value. So far, I have the following which works just fine one value of c.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;  
   use test; read all;
proc phreg data = test;
    ods output FitStatistics=Output noprint;
    model times * dead(0) = sexE sexL;
    c = 1;
    if times &amp;lt;= c and sex = 1 then sexE=1; else sexE=0;
    if times &amp;gt; c and sex = 1 then sexL=1; else sexL=0;
 run; 

proc print data=Output noobs;
run;
data _null_;
    set Output;
    if Criterion="-2 LOG L" then call symputx("value",WithCovariates);
run;

%put value= &amp;amp;value;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Any help would be appreciated. Thanks.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 20:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Calling-PROC-PHREG-multiple-times/m-p/686514#M33058</guid>
      <dc:creator>themanoj20080</dc:creator>
      <dc:date>2020-09-24T20:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: Calling PROC PHREG multiple times</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Calling-PROC-PHREG-multiple-times/m-p/686531#M33059</link>
      <description>&lt;P&gt;Instead of running the proc multiple times, expand your data set and then run the PROC PHREG once with a BY statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test_large;
set have;
 do c=1 to 50;
   if times &amp;lt;= c and sex = 1 then sexE=1; else sexE=0;
    if times &amp;gt; c and sex = 1 then sexL=1; else sexL=0;
   output;
end;
run;

proc sort data=test_large;
by c;
run;

proc phreg data=........
BY C;
*everything else here is the same minus the manual coding of the variable;
....
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Sep 2020 21:11:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Calling-PROC-PHREG-multiple-times/m-p/686531#M33059</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-24T21:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: Calling PROC PHREG multiple times</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Calling-PROC-PHREG-multiple-times/m-p/686536#M33060</link>
      <description>&lt;P&gt;Thank you for the reply. Actually, the manual coding of the variable needs to be inside the proc phreg. Otherwise, the results are not the same.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 21:26:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Calling-PROC-PHREG-multiple-times/m-p/686536#M33060</guid>
      <dc:creator>themanoj20080</dc:creator>
      <dc:date>2020-09-24T21:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: Calling PROC PHREG multiple times</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Calling-PROC-PHREG-multiple-times/m-p/686548#M33061</link>
      <description>&lt;P&gt;Then you'll need a macro or CALL EXECUTE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's an example in this tutorial that's fairly close to what you're trying to do UCLA introductory tutorial on macro variables and macros&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Tutorial on converting a working program to a macro&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 21:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Calling-PROC-PHREG-multiple-times/m-p/686548#M33061</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-24T21:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calling PROC PHREG multiple times</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Calling-PROC-PHREG-multiple-times/m-p/686663#M33068</link>
      <description>&lt;P&gt;Our shop does this a lot.&amp;nbsp; If you don't have an indicator variable for each dataset, you will need to create one.&amp;nbsp; Then you can do something like the following (NOTE: This is a different PROC, so look at the various ODS table names for PHREG to get what you want..):&lt;/P&gt;
&lt;P&gt;This part generates the by variables and merges them back onto the original dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Process anlsdat byvar*/
proc sort data=anlsdatin out=byvars (keep = paramid parameter) nodupkey;
    by paramid parameter;
run;

data byvars;
    set byvars end=eof;
    by paramid parameter;

    byvar = _N_;

    if eof then call symputx('LastByVar', _N_);
run;

proc sort data=anlsdatin;
    by paramid parameter;
run;

data anlsdat;
    merge anlsdatin byvars;
    by paramid parameter;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This extracts the fit information from the PROC (GLIMMIX here):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro runtimes();
%do b=2 %to &amp;amp;LastByVar;
proc sort data=anlsdat (where=(byvar=&amp;amp;b.)) out=anlsdat_&amp;amp;b.;
by byvar paramid parameter grp_no sex animal;
run;

%macro runtests(covtype=, it=);

proc glimmix data=anlsdat_&amp;amp;b. method = laplace;
nloptions maxiter = 5000;
by byvar paramid parameter;
class grp_no sex animal;
model value = grp_no sex grp_no*sex / dist = gamma ddfm=bw;
random grp_no / type = &amp;amp;covtype. subject=animal;
ods output fitstatistics = _rm_fit_&amp;amp;b._&amp;amp;it._1 convergencestatus=_convdat1_&amp;amp;b._&amp;amp;it._1;
run;

data _rm_fit_&amp;amp;b._&amp;amp;it._1;
length covtype $10 value 8 descr $100;
%if %sysfunc(exist(_rm_fit_&amp;amp;b._&amp;amp;it._1)) %then %do; set _rm_fit_&amp;amp;b._&amp;amp;it._1; %end;
covtype = "&amp;amp;covtype.";
Distribution="Gamma";
run;

%mend runtests;/*
%runtests(covtype=CSH, it=1);
%runtests(covtype=CHOL, it=2);

data fit&amp;amp;b.;
set _rm_fit_&amp;amp;b.:;
run;

proc datasets nolist lib=work;
delete _rm_fit_&amp;amp;b.:;
run;

proc sort data=fit&amp;amp;b. out=checkcov&amp;amp;b. (where=(lowcase(descr) = "aicc (smaller is better)" or lowcase(descr) = "aicc (smaller is better)"));
by value;
run;

%let cs = 0;
%let dist = ;
/*
data checkcov&amp;amp;b.;
%if %sysfunc(exist(checkcov&amp;amp;b.)) %then %do; 
set checkcov&amp;amp;b.;
%end;

if _N_ = 1 then do;
call symputx('cs', covtype);
call symputx('dist', Distribution);
selected = 1;
end;
run;
*/
%if "&amp;amp;cs" = "0" %then %do;
%let cs = UN(1);
%let dist = Gamma;
%end;&lt;BR /&gt;%mend&amp;nbsp;runtimes&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use this, be sure that all the %do loops are closed, as I have edited out some things we would rather keep proprietary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SteveDenham&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 10:57:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Calling-PROC-PHREG-multiple-times/m-p/686663#M33068</guid>
      <dc:creator>SteveDenham</dc:creator>
      <dc:date>2020-09-25T10:57:26Z</dc:date>
    </item>
  </channel>
</rss>

