Hi all
I would like to automatically use a value, derived from an output database, into a new data step.
I explain with an example:
proc logistic data=sample plots=none;
model Y(event=1)=X / outroc=rocX;
ods output ParameterEstimates=param;
run;
/*param DBS has two columns, Variable (in this example named Intercept and X) and Estimate*/
I would like to automatically include the value of Intercept and X, taken from the dbs param, into the following DATA Step
data rocX2(keep=cutoff prob Sensitivity Specificity Youden);
set rocX;
logit=log(_prob_/(1-_prob_));
cutoff=(logit-/*Intercept*/)//*X*/;
prob=_prob_;
Sensitivity=_SENSIT_;
Specificity=1-_1MSPEC_;
Youden=_SENSIT_+ (1-_1MSPEC_)-1;
run;
tsk in advance
@antor82 wrote:
From the first PROC logistic I derived two parameter estimates for the model Y=X, namely Intercept and X.
I need to put the value of Intercept and X into the formula
cutoff=(logit-valueofintercept)/betaofX
The values of intercept and of beta for X have been saved in
ods output ParameterEstimates=param
I’ve already done it by hand
The formula became
cutoff=(logit-13.043)/-0.537
But I wonder if I could do this automatically
data rocX2;
if _n_=1 then merge param(where=(variable='Intercept') rename=(estimate=intercept))
param(where=(variable='X') rename=(estimate=beta1));
set rocX;
logit=log(_prob_/(1-_prob_));
cutoff=(logit-intercept/beta1);
data rocX2(keep=cutoff prob Sensitivity Specificity Youden);
if _n_=1 then set param;
set rocX;
logit=log(_prob_/(1-_prob_));
cutoff=(logit-/*Intercept*/)//*X*/;
prob=_prob_;
Sensitivity=_SENSIT_;
Specificity=1-_1MSPEC_;
Youden=_SENSIT_+ (1-_1MSPEC_)-1;
run;
@antor82 wrote:
What should I change /*Intercept*/ with?
I don't know, since I don't know what you want to do. I don't know what the formula for CUTOFF is supposed to do.
@antor82 wrote:
From the first PROC logistic I derived two parameter estimates for the model Y=X, namely Intercept and X.
I need to put the value of Intercept and X into the formula
cutoff=(logit-valueofintercept)/betaofX
The values of intercept and of beta for X have been saved in
ods output ParameterEstimates=param
I’ve already done it by hand
The formula became
cutoff=(logit-13.043)/-0.537
But I wonder if I could do this automatically
data rocX2;
if _n_=1 then merge param(where=(variable='Intercept') rename=(estimate=intercept))
param(where=(variable='X') rename=(estimate=beta1));
set rocX;
logit=log(_prob_/(1-_prob_));
cutoff=(logit-intercept/beta1);
I have no idea what you mean by "printed twice". Show me.
Tks for support!
Following is the result of a proc print from dataset param (consider VS_LVEF as X in our previous post)
Replicate Variable Estimate
1 | Intercept | 11.5259 |
1 | VS_LVEF | -0.2393 |
1 | Intercept | 11.5259 |
1 | VS_LVEF | -0.2393 |
2 | Intercept | 24.7332 |
2 | VS_LVEF | -0.4754 |
2 | Intercept | 24.7332 |
2 | VS_LVEF | -0.4754 |
3 | Intercept | 7.8117 |
3 | VS_LVEF | -0.1531 |
3 | Intercept | 7.8117 |
3 | VS_LVEF | -0.1531 |
4 | Intercept | 27.1324 |
4 | VS_LVEF | -0.5119 |
4 | Intercept | 27.1324 |
4 | VS_LVEF | -0.5119 |
5 | Intercept | 17.5613 |
5 | VS_LVEF | -0.3322 |
5 | Intercept | 17.5613 |
5 | VS_LVEF | -0.3322 |
the variable Replicate comes from a bootstrap.
As You can see, for Replicate n.1 I have twice a Estimate for the Variable Intercept and twice for VS_LVEF. While I need only 1 Intercept estimate and only 1 VS_LVEF estimate. And so on for the other Replicates...
Furthermore, when I run the suggested code
data rocX2; if _n_=1 then merge param(where=(variable='Intercept') rename=(estimate=intercept)) param(where=(variable='X') rename=(estimate=beta1)); set rocX; logit=log(_prob_/(1-_prob_)); cutoff=(logit-intercept/beta1);
the result is attached to this reply.
Briefly:
1) first 39 obs are ok. Obs from 40 to 79 duplicate the previous obs for Replicate n.1;
2) As You can see, the value for Intercept and Beta are the same for ALL replicates!
Tks a lot!
A
Replicate has never been mentioned in this thread before your last post. Please explain.
Whatever code I gave you is not going to work with a Replicate variable.
It seems as if we need to start from scratch, and you need to show me the code (and part of the data) that contains replicate.
I tried to manage this way... and worked
/*put estimates in a single row per each replicate*/
/*one column per "intercept", another per "beta"*/
PROC SORT data=param out=paramsorted;
BY Replicate;
RUN;
PROC TRANSPOSE data=paramsorted
out=transposed name=Variable;
BY replicate;
VAR estimate;
RUN;
data transposed;
set transposed;
rename COL1=Intercept COL2=Beta;
keep replicate intercept beta;
run;
/*remove duplicate data from output dataset (have both Model and X in the _SOURCE_ column)*/
data rocX2;
set rocX2;
where _SOURCE_='Model';
run;
Attached is a print of the transposed dataset
Then I performed the desired analysis
data rocX3 (keep=cutoff Sensitivity Specificity Youden intercept beta replicate);
merge transposed rocX2;
by replicate;
logit=log(_prob_/(1-_prob_));
cutoff=(logit-intercept)/beta;
prob=_prob_;
Sensitivity=_SENSIT_;
Specificity=1-_1MSPEC_;
Youden=_SENSIT_+ (1-_1MSPEC_)-1;
run;
and this worked too.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.