<?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: PROC NLIN changing initial conditions in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/PROC-NLIN-changing-initial-conditions/m-p/884291#M39247</link>
    <description>&lt;P&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;!!&lt;BR /&gt;&lt;BR /&gt;One more questions for you. Now I have this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc nlin data = participant_data g4 plots = fit maxiter = 50 outest = params_out;
by subject;
parameters / pdata=init_params;
model response = a*exp(time/b) + c*time + d;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but actually I need that a+d = value. So:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc nlin data = participant_data g4 plots = fit maxiter = 50 outest = params_out;
by subject;
parameters / pdata=init_params;
bounds d+a = value;
model response = a*exp(time/b) + c*time + d;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that value is different for each SUBJECT. How do I do?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jul 2023 08:58:24 GMT</pubDate>
    <dc:creator>linlin87</dc:creator>
    <dc:date>2023-07-11T08:58:24Z</dc:date>
    <item>
      <title>PROC NLIN changing initial conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-NLIN-changing-initial-conditions/m-p/884058#M39239</link>
      <description>&lt;P&gt;Hi SAS community&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have data over time for ~200 participants. For each participant, I want to fit the same model, but I have a different set of initial conditions for the PROC NLIN routine (derived by looking at data for each paritcipant). How do I get this to work (code below)? Any help really appreciate. I keep get error like this:&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;NOTE: DER.a not initialized or missing. It will be computed automatically.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;NOTE: DER.b not initialized or missing. It will be computed automatically.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;NOTE: DER.c not initialized or missing. It will be computed automatically.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;NOTE: DER.d not initialized or missing. It will be computed automatically.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;WARNING: Zero observations could be evaluated.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;NOTE: The data set WORK.PARAMS_OUT_4 has 0 observations and 9 variables.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data initial_params;
set in.initial_params;
nf+1;
call symputx("last_nf",nf);
run;

data participant_data;
set in.participant_data;
run;

%macro fit;
%do j=1 %to &amp;amp;last_nf.;

data _null_; 
 	set initial_params;
 	where nf=&amp;amp;j;
 	call symputx("beta10",beta10);
	call symputx("beta20",beta20);
	call symputx("beta30",beta30);&lt;BR /&gt;    call symputx("beta40".beta40);
	call symputx("participant",subject); 
run;
proc nlin data = participant_data g4 plots = fit maxiter = 50 outest = params_out_&amp;amp;j.;
where subject="&amp;amp;participant";
parameters a = &amp;amp;beta10. &amp;amp;beta20. = -3 c = &amp;amp;beta30. d = &amp;amp;beta40.;
model response = a*exp(time/b) + c*time + d;
run;

%end;

%mend;

%fit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;suggesting what I do wrong would be very helpful to me!&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jul 2023 19:17:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-NLIN-changing-initial-conditions/m-p/884058#M39239</guid>
      <dc:creator>linlin87</dc:creator>
      <dc:date>2023-07-08T19:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: PROC NLIN changing initial conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-NLIN-changing-initial-conditions/m-p/884060#M39241</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/426087"&gt;@linlin87&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of all, I see two syntax errors in your code which would prevent the PROC NLIN step from even producing the messages you show:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The period between &lt;FONT face="courier new,courier"&gt;"beta40"&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;beta40&lt;/FONT&gt; in the fourth CALL SYMPUTX of the DATA _NULL_ step must be a comma.&lt;/LI&gt;
&lt;LI&gt;Instead of &lt;FONT face="courier new,courier"&gt;&amp;amp;beta20. = -3&lt;/FONT&gt;&amp;nbsp;in the PARAMETERS statement I would rather expect something like &lt;FONT face="courier new,courier"&gt;b = &amp;amp;beta20.&lt;/FONT&gt; (or does macro variable &lt;FONT face="courier new,courier"&gt;BETA20&lt;/FONT&gt; contain a variable name such as &lt;FONT face="courier new,courier"&gt;b&lt;/FONT&gt;?).&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;One situation in which the warning "&lt;SPAN&gt;Zero observations could be evaluated" would occur is that the WHERE condition&amp;nbsp;&lt;FONT face="courier new,courier"&gt;subject="&amp;amp;participant"&lt;/FONT&gt; is not met for any observation of dataset&amp;nbsp;PARTICIPANT_DATA. So, make sure that those character values match exactly.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;But most importantly, I think you could both simplify your program and make it more robust if you used a single PROC NLIN step with a BY statement (&lt;FONT face="courier new,courier"&gt;by subject&lt;/FONT&gt;) instead of the macro, macro variables and the WHERE condition. Then you could name the dataset containing the subject-specific initial parameter values in the PDATA= option of the PARAMETERS statement. See the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/statug/statug_nlin_syntax12.htm" target="_blank" rel="noopener"&gt;syntax&lt;/A&gt; and section "&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/statug/statug_nlin_syntax12.htm#statug_nlin002515" target="_blank" rel="noopener"&gt;Assigning Starting Values from a SAS Data Set&lt;/A&gt;" in the PROC NLIN documentation.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Edit: Below is an example of what your PROC NLIN step could look like. Note the structure of the PDATA= dataset (which I named &lt;FONT face="courier new,courier"&gt;init_params&lt;/FONT&gt;).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create test data for demonstration */

data temp;
input subject a b c d;
cards;
1  8 2 0.2  1
2  7 1 0.3 -1
;

proc transpose data=temp out=init_params(rename=(col1=estimate)) name=parameter;
by subject;
run;

data participant_data(drop=a--d);
set temp;
do time=1 to 5;
  response=a*exp(time/b) + c*time + d + rannor(1);
  output;
end;
run;

/* Use BY-group processing and the PDATA= option in PROC NLIN */

proc nlin data = participant_data g4 plots = fit maxiter = 50 outest = params_out;
by subject;
parameters / pdata=init_params;
model response = a*exp(time/b) + c*time + d;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jul 2023 21:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-NLIN-changing-initial-conditions/m-p/884060#M39241</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-07-08T21:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: PROC NLIN changing initial conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-NLIN-changing-initial-conditions/m-p/884291#M39247</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;!!&lt;BR /&gt;&lt;BR /&gt;One more questions for you. Now I have this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc nlin data = participant_data g4 plots = fit maxiter = 50 outest = params_out;
by subject;
parameters / pdata=init_params;
model response = a*exp(time/b) + c*time + d;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but actually I need that a+d = value. So:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc nlin data = participant_data g4 plots = fit maxiter = 50 outest = params_out;
by subject;
parameters / pdata=init_params;
bounds d+a = value;
model response = a*exp(time/b) + c*time + d;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that value is different for each SUBJECT. How do I do?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 08:58:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-NLIN-changing-initial-conditions/m-p/884291#M39247</guid>
      <dc:creator>linlin87</dc:creator>
      <dc:date>2023-07-11T08:58:24Z</dc:date>
    </item>
    <item>
      <title>Re: PROC NLIN changing initial conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-NLIN-changing-initial-conditions/m-p/884326#M39248</link>
      <description>&lt;P&gt;You're welcome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the BOUNDS statement is more suitable for constraints in the form of &lt;EM&gt;inequalities&lt;/EM&gt; about the parameters. Given that all these numbers are non-integers, an &lt;EM&gt;exact&lt;/EM&gt; equality such as &lt;FONT face="courier new,courier"&gt;d+a=value&lt;/FONT&gt;&amp;nbsp;would be a risky requirement anyway. (Note that, e.g.,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;0.1+0.2 ne 0.3&lt;/FONT&gt; in Windows SAS due to rounding errors in the binary system.) Also, the BOUNDS statement, unlike the PARAMETERS statement, does not allow for varying values coming from a dataset. There is a different procedure, &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/statug/statug_hpnlin_toc.htm" target="_blank" rel="noopener"&gt;PROC HPNLMOD&lt;/A&gt;, which offers a &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/statug/statug_hpnlin_syntax11.htm" target="_blank" rel="noopener"&gt;RESTRICT statement&lt;/A&gt; where you could specify your linear constraint. But I have never used PROC HPNLMOD before today, so let's stay with PROC NLIN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In PROC NLIN it's probably better to implement the constraint&amp;nbsp;&lt;FONT face="courier new,courier"&gt;d+a=value&lt;/FONT&gt; in the model equation. You have two options for that: Either replace &lt;FONT face="courier new,courier"&gt;d&lt;/FONT&gt; with &lt;FONT face="courier new,courier"&gt;value-a&lt;/FONT&gt;, or replace &lt;FONT face="courier new,courier"&gt;a&lt;/FONT&gt; with &lt;FONT face="courier new,courier"&gt;value-d&lt;/FONT&gt;. Let's follow the first approach, i.e., &lt;EM&gt;eliminate&lt;/EM&gt; parameter &lt;FONT face="courier new,courier"&gt;d&lt;/FONT&gt; in the model equation and introduce &lt;FONT face="courier new,courier"&gt;value&lt;/FONT&gt; as a new variable (not parameter) in the input dataset&amp;nbsp;&lt;FONT face="courier new,courier"&gt;participant_data&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the example from my earlier post, with the new constraint implemented. Changes are highlighted in blue.&lt;/P&gt;
&lt;PRE&gt;/* Create test data for demonstration */

data temp;
input subject a b c &lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;value&lt;/STRONG&gt;&lt;/FONT&gt;; &lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;/* parameter d has been eliminated by the constraint d+a=value */&lt;/FONT&gt;&lt;/STRONG&gt;
cards;
1  8 2 0.2 &lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;9&lt;/STRONG&gt;&lt;/FONT&gt;
2  7 1 0.3 &lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;6&lt;/STRONG&gt;&lt;/FONT&gt;
;

proc transpose data=temp&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;(drop=value)&lt;/STRONG&gt;&lt;/FONT&gt; out=init_params(rename=(col1=estimate)) name=parameter;
by subject;
run;

data participant_data(drop=a--&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;c&lt;/STRONG&gt;&lt;/FONT&gt;);
set temp;
do time=1 to 5;
  response=a*exp(time/b) + c*time + &lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;value - a&lt;/STRONG&gt;&lt;/FONT&gt; + rannor(1);
  output;
end;
run;

/* Use BY-group processing and the PDATA= option in PROC NLIN */

proc nlin data = participant_data g4 plots = fit maxiter = 50 outest = params_out;
by subject;
parameters / pdata=init_params;
model response = a*exp(time/b) + c*time + &lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;value - a&lt;/STRONG&gt;&lt;/FONT&gt;;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see in dataset &lt;FONT face="courier new,courier"&gt;participant_data&lt;/FONT&gt;, variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;value&lt;/FONT&gt; is a subject-dependent constant over time. Parameters &lt;FONT face="courier new,courier"&gt;a&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;b&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;c&lt;/FONT&gt; are estimated, starting with (unchanged) subject-specific initial values from dataset &lt;FONT face="courier new,courier"&gt;init_params&lt;/FONT&gt;, as before. For each subject, you could use the estimate for&amp;nbsp;parameter &lt;FONT face="courier new,courier"&gt;a&lt;/FONT&gt; computed by PROC NLIN and the known value of variable &lt;FONT face="courier new,courier"&gt;value&lt;/FONT&gt;&amp;nbsp;to compute &lt;FONT face="courier new,courier"&gt;d = value - a&lt;/FONT&gt;, if needed:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data est(drop=_:);
set params_out;
where _type_='FINAL';
run;

data values;
set participant_data(keep=subject value);
by subject;
if first.subject;
run;

data want;
merge values est;
by subject;
d=value-a;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obviously, the estimates will satisfy the constraint&amp;nbsp;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;a+d = value&lt;/FONT&gt;, possibly up to tiny rounding differences like 1E-16 as in this example:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;138   data _null_;
139   d=0.9-0.3;
140   if 0.3+d ne 0.9 then put 'Surprised?';
141   delta=0.3+d-0.9;
142   put delta=;
143   run;

Surprised?
delta=1.110223E-16&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Jul 2023 12:23:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-NLIN-changing-initial-conditions/m-p/884326#M39248</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-07-11T12:23:46Z</dc:date>
    </item>
  </channel>
</rss>

