## Proc model solve for X preserving sample size

Super Contributor
Posts: 328

# Proc model solve for X preserving sample size

data CP;

input t s uu;

cards;

1  2  3

0 2   3

0  3  3

1  2  2

1  4  5

;

proc model data=CP ;

where t=1;

eq.sn=(UU- exp(s-tc)**2;

solve tc/out=myso;

run;

The data set myso will be like this:

 1 PREDICT SIMULATE 0 1.48371 3 2 2 PREDICT SIMULATE 0 -7.60045 2 2 3 PREDICT SIMULATE 0 -7.60045 5 4

However I want a data with all the observations including the  the cases where t=0.

I tried this but it it was not good:

proc model data=CP ;

tc=s;

where t=1;

eq.sn=(UU- exp(s-tc)**2;

solve tc/out=myso;

run;

Super User
Posts: 13,583

## Re: Proc model solve for X preserving sample size

Remove the Where t=1; statement perhaps?

Super Contributor
Posts: 328

It does not work

Posts: 5,543

## Re: Proc model solve for X preserving sample size

data CP;

input t s uu;

cards;

1  2  3

0  2  3

0  3  3

1  2  2

1  4  5

;

proc model data=CP plots=none;

UU = exp(s-tc);

fit UU parms=(tc) / out=myso outall;

weight t;

run;

PG

PG
Super Contributor
Posts: 328

## Re: Proc model solve for X preserving sample size

Thanks PGStats, I am running this withing a simulation. THis is the code:

proc model data=CP_est_&u plots=none;

UU=-exp(-(k-alpha1*timec)**2/2*Sigma**2))*(1-SURVIVAL1)+(exp(-(k-alpha1*timec)**2/2*Sigma**2))*(k*alpha1-alpha1**2*timec)*(1-SURVIVAL1)-ht_sum;

fit UU parms=(timec) / out=myso_&u outall;

weight timec;

run;

However, no data is created, instead I have the following error:

WARNING: Limit set by ERRORS= option reached.  Further errors of this type will not be printed.

alpha0=2.57016 alpha1=2.23407 alpha2=4.01224 sigma=0.15054 beta=0.60420 lambda=1.830 Replicate=1

X=1 time=0.0093138115 censored=0 obs=1 y=6.8196847642 NumberHits=2 survival=0.7772239588

ht_Sum=0.1105307015 SURVIVAL1=0.7772239588 pi=3.1415926536 k=-23.39127707 CD=-0.134368884

M=0.9482803906 N=. P=. Z=-0.1062101 _ERROR_=1 _N_=36

233   plots=none;

233! UU=-exp(-(k-alpha1*timec)**2/2*Sigma**2))*(1-SURVIVAL1)+(exp(-(k-alpha1*timec)**2/2*Sigma**2)

Posts: 5,543

## Re: Proc model solve for X preserving sample size

You cannot estimate timec and use it as a weight. Also, for testing, replace macro variable &u invocation with a fixed value. - PG

PG
Posts: 5,543

## Re: Proc model solve for X preserving sample size

Looking at your equation, I suspect that the expression 2*Sigma**2 should be within parentheses at both places where it appears. - PG

PG
Super Contributor
Posts: 328

## Re: Proc model solve for X preserving sample size

Hello ,

proc model data=CP_est_&u plots=none;

UU=-exp(-(k-alpha1*timec)**2/(2*Sigma**2))*(1-SURVIVAL1)+(exp(-(k-alpha1*timec)**2/2*Sigma**2))*(k*alpha1-alpha1**2*timec)*(1-SURVIVAL1)-ht_sum;

fit UU parms=(timec) / out=myso_&u outall;

weight censored;

run;

However, it didnt solve for timec. This is the output. It is not solving for timec,

 Obs _ESTYPE_ _TYPE_ _WEIGHT_ censored UU k alpha1 sigma SURVIVAL1 1 OLS ACTUAL 0 0 0.5 1.0804 1.457 0.23373 0.99018 2 OLS PREDICT 0 0 -0.07263 1.0804 1.457 0.23373 0.99018 3 OLS RESIDUAL 0 0 0.57263 1.0804 1.457 0.23373 0.99018 4 OLS ACTUAL 1 1 -0.01835 -0.5053 1.457 0.23373 0.9851 5 OLS PREDICT 1 1 -0.09713 -0.5053 1.457 0.23373 0.9851 6 OLS RESIDUAL 1 1 0.07878 -0.5053 1.457 0.23373 0.9851 7 OLS ACTUAL 1 1 -0.00915 4.8146 1.457 0.23373 0.98257 8 OLS PREDICT 1 1 -0.00303 4.8146 1.457 0.23373 0.98257 9 OLS RESIDUAL 1 1 -0.00612 4.8146 1.457 0.23373 0.98257
Posts: 5,543

## Re: Proc model solve for X preserving sample size

Now I think I understand. You simply want to find the value of timec that solves the equation for each observation of your dataset when t=1. This should be close to what you want:

data test;
input obs t UU k alpha1 sigma SURVIVAL1 ht_sum;
datalines;
1 1 -0.01835 -0.5053 1.457 0.23373 0.9851 0.01
2 0  0.01835 -0.5053 1.457 0.23373 0.9851 0.01
;

proc model plots=none noprint;
id obs t;
UU = exp(-(k-alpha1*timec)**2/(2*Sigma**2))*(1-SURVIVAL1) * (alpha1*(k - alpha1*timec) - 1) - ht_sum;
solve timec satisfy=(UU) / data=test(where=(t)) out=testOut;
run;

proc sql;
create table testSol as
select * from test natural left join testOut
order by obs;
select * from testsol;
quit;

You could also use the SOLVE function of proc fcmp to do this.

PG

PG
Super Contributor
Posts: 328

## Re: Proc model solve for X preserving sample size

Happy New year. Thanks for the great help. Your code runs well. However, when I try to transfer it to simulation in which I am trying to run, it did not work. This is what I got:

proc model plots=CP_est_&u noprint;

UU=-exp(-(k-alpha1*timec)**2/(2*Sigma**2))*(1-SURVIVAL1)-(exp(-(k-alpha1*timec)**2/2*Sigma**2))*(k*alpha1-alpha1**2*timec)*(1-SURVIVAL1)-ht_sum;

solve timec satisfy=(UU) / data=myso_&u(where=(censored)) out=testOut_&u;

run;

proc sql;

create table testSol_&u as

select * from myso_&u natural left join testOut_&u

order by time;

select * from testsol_&u;

quit;

I am testing a model and can only do it within a simulation set up. I macro runs well up till the steps above. Any help how to make it work within simulation

Thanks

Folefac

Posts: 5,543

## Re: Proc model solve for X preserving sample size

What messages did you get? To get your code to work, you will at least need to replace plots=CP_est_&u by plots=none, change data=myso_&u to data=CP_est_&u, put the second instance of 2*Sigma**2 within parentheses and add statement

ID time;

PG

PG
Super Contributor
Posts: 328

## Re: Proc model solve for X preserving sample size

Hi This is what I got thanks to your corrections:

It does not run.

proc model plots=none noprint;

id time censored;

UU=-exp(-(k-alpha1*timec)**2/(2*Sigma**2))*(1-SURVIVAL1)-(exp(-(k-alpha1*timec)**2/2*Sigma**2))*(k*alpha1-alpha1**2*timec)*(1-SURVIVAL1)-ht_sum;

solve timec satisfy=(UU) / data=CP_est_&u (where=(censored)) out=testOut_&u;

run;

proc sql;

create table testSol_&u as

select * from CP_est_&u natural left join testOut_&u

order by time;

select * from testsol_&u;

quit;

NOTE: There were 100 observations read from the data set WORK.CPH_EST_11.

NOTE: The data set WORK.CP_EST_11 has 100 observations and 24 variables.

NOTE: DATA statement used (Total process time):

real time           0.00 seconds

cpu time            0.01 seconds

ERROR: The solution did not converge for observation 1 after 4 NEWTON iterations using the

convergence criterion CONVERGE=1E-8.

NOTE: The data set WORK.TESTOUT_11 has 1 observations and 12 variables.

NOTE: PROCEDURE MODEL used (Total process time):

real time           0.10 seconds

cpu time            0.03 seconds

NOTE: Table WORK.TESTSOL_11 created, with 100 rows and 28 columns.

NOTE: PROCEDURE SQL used (Total process time):

real time           0.13 seconds

cpu time            0.14 seconds

NOTE: Variable timeC is uninitialized.

NOTE: There were 100 observations read from the data set WORK.CPH_EST_11.

NOTE: The data set WORK.IMPUTE_TT_11 has 100 observations and 24 variables.

NOTE: DATA statement used (Total process time):

real time           0.00 seconds

cpu time            0.00 seconds

THIS IS  HOW THE DATA IS LIKE: IT DIDNT WORK the way I wanted, timec is all set to missing

 time censored UU k alpha1 Sigma SURVIVAL1 ht_sum _TYPE_ _MODE_ _ERRORS_ timec 3.59E-05 0 0.5 -9.898 1.05082 0.18574 0.9802 -0.0494 . . 3.59E-05 1 0.5 -9.898 1.05082 0.18574 0.9802 -0.0494 . . 5.08E-05 0 0.5 0.52633 1.05082 0.18574 0.95065 -0.0494 . . 5.08E-05 0 0.5 0.52633 1.05082 0.18574 0.95065 -0.0494 . . 5.08E-05 0 0.5 0.52633 1.05082 0.18574 0.95065 -0.0494 . . 0.000271 0 0.5 -5.3521 1.05082 0.18574 0.9407 -0.0494 . . 0.000548 0 0.5 -4.9686 1.05082 0.18574 0.9209 -0.0494 . . 0.000548 0 0.5 -4.9686 1.05082 0.18574 0.9209 -0.0494 . . 0.000576 1 0.5 6.33329 1.05082 0.18574 0.90109 -0.0494 . . 0.000576 1 0.5 6.33329 1.05082 0.18574 0.90109 -0.0494 . .
Posts: 5,543

## Re: Proc model solve for X preserving sample size

Proc Model could not find the solution, possibly because of the missing parentheses (added in red) in your equation

UU=-exp(-(k-alpha1*timec)**2/(2*Sigma**2))*(1-SURVIVAL1)-(exp(-(k-alpha1*timec)**2/(2*Sigma**2)))*(k*alpha1-alpha1**2*timec)*(1-SURVIVAL1)-ht_sum;

There is also the possibility that some parameter combinations do not have a solution for timec.

PG

PG
Super Contributor
Posts: 328

## Re: Proc model solve for X preserving sample size

THis works:

data test;

input obs t UU k alpha1 sigma SURVIVAL1 ht_sum time ;

datalines;

1 1  0.01835  0.5053 1.457 0.23373 0.9851 0.01  .000520410

2 0  0.01835  0.2053 1.457 0.23373 0.9851 0.01  .000690482

3 1  0.03835  0.3053 1.457 0.23373 0.9851 0.01  .000690482

4 0  0.02835  0.1053 1.457 0.23373 0.9851 0.01  .001781026

;

proc model plots=none noprint;

id time t;

UU=-exp(-(k-alpha1*timec)**2/(2*Sigma**2))*(1-SURVIVAL1)-(exp(-(k-alpha1*timec)**2/2*Sigma**2))*(k*alpha1-alpha1**2*timec)*(1-SURVIVAL1)-ht_sum;

solve timec satisfy=(UU) / data=test(where=(t)) out=testOut;

run;

proc sql;

create table testSol as

select * from test natural left join testOut

order by time;

select * from testsol;

quit;

 time t UU k alpha1 Sigma SURVIVAL1 ht_sum Type of Observation Solution Mode Execution Error timec obs Count 0.00052 1 0.0184 0.5053 1.457 0.23373 0.9851 0.01 PREDICT SIMULATE 0 6 1 0.00069 1 0.0384 0.3053 1.457 0.23373 0.9851 0.01 PREDICT SIMULATE 0 4.4 3 0.00069 0 0.0184 0.2053 1.457 0.23373 0.9851 0.01 . . 2 0.00178 0 0.0284 0.1053 1.457 0.23373 0.9851 0.01 . . 4
Super Contributor
Posts: 328