PROC PHREG - survival probability at specific point of time - sas

I'm making a model in SAS using proc phreg procedure. In the output out statement it is possible to define a survival variable for each observation. This survival variable is the probability of survival until some point of time. My question is: what time is considered here? Is it a probability of surviving until time=0?
Is it possible to get a variable like this but describing a probability of surviving until some arbitraty defined point of time? (i.e. 1 year?)
My code is following:
ods graphics on;
proc phreg data=train outest=estimates plots=(survival cumhaz);
class &vars;
model time*censor(1)=&vars / selection=stepwise ties=efron;
output out=surv survival=s;
run;
ods graphics off;
Thank you in advance!

Related

SAS output confidence interval to plot for strata variable after logistic regression

I want to put all confidence interval plot in one plot for all strata variable after logistic regression. For example, my SAS code is:
proc logistic data=data1;
model y = x;
strata cv1;
output out=out1 unknown1=x_beta1 unknown2=lowerbound unknown3=upperbound unknown4=strata_variable;
run;
I do not know what variable names(unknown1 unknown2 unknown3) I can use in the output statement. As in the sas support page, it said "If a STRATA statement is specified, only the PREDICTED=, DFBETAS=, and H= options are available",here is the link.
My plot statement will be:
proc sgplot data=out1;
scatter y=strata_variable x=x_beta1 / xerrorlower=lowerbound xerrorupper=upperbound
markerattrs=(symbol=circlefilled size=9);
run;
The first plot in this page shows exactly what I want. Sorry I cannot insert any plot as my reputation is not high enough.
I find an another way to finish this. I wrote a macro do loop to get every strata data. And then added
ods output OddsRatios=odds_temp;
to get the estimation and confidence interval and merger all the strata together to make the plot I need.

Obtain the smoothed hazard estimates

How can I obtain a data set or table with the smoothed hazard estimates and the 95% confidence intervals with time which are displayed when I run for example
ods graphics on;
proc lifetest data=melanoma34 plots=(h(cl));
time weeks*censor(1);
run;
EDIT
This is what I run
data melanoma34;
infile '/folders/myfolders/amsus/data/melanoma34.dat';
input weeks status$;
if status='alive' then censor=1;
else censor=0;
run;
Proc lifetest data=Melanoma34 outsurv=hazards;
time weeks*censor(1);
ods output hazardplot=smoothedhazard;
run;
and the hazards outsurv does not contain the smoothed hazard estimates
. The data can be found here under /amsus/data/
The outsurv data set contains the hazard function estimates and the confidence interval.
Proc lifetest data=Melanoma outsurv=hazards;
EDIT:
The above generates an estimate for the hazard function, not the smoothed estimate and only works for method=LT.
To obtain the smooth estimate, using method=KM (default), then use the following line:
ods output hazardplot=smoothedhazard;
Final code:
data melanoma34;
infile '/folders/myfolders/amsus/data/melanoma34.dat';
input weeks status$;
if status='alive' then censor=1;
else censor=0;
run;
Proc lifetest data=Melanoma34 plots=h(cl));
time weeks*censor(1);
ods output hazardplot=smoothedhazard;
run;

Renaming Coefficients that Result from Proc Logistic/Problems Surrounding Variable Names Common to Multiple Datasets

I am estimating a model for firm bankruptcy that involves 11 factors. I have data from 1900 to 2000 and my goal is to estimate my model using proc logistic for the period 1900-1950 and then test its performance on the 1951 through 2000 data. Proc logistic runs fine but the problem I have is that the estimated coefficients have the same name as my factors that I was using in my model. Suppose the dataset that contains all my observations is called myData and the dataset that contains the estimated coefficients which I obtain using an outtest statement (in proc logistic) is called factorEstimates. Now both of these data sets have the variables factor1, factor2, ..., factorN. Now I want to form the dataset outOfSampleResults that does something like the following:
data outOfSampleResults;
set myData factorEstimates;
newVar=factor1*factor1;
run;
Where the first mention of factor1 refers to that contained in myData and the second refers to that contained in factorEstimates. How can I inform sas which dataset it should read for this variable that is common to both of the datasets in the set statement? Alternatively, how could I quickly rename factor1, factor2, ..., factorN as factor1Estimate, factor2Estimate, ..., factorNEstimate in the factorEstimates dataset so as to circumvent this common variable name issue altogether?
Two quick ways to get estimates for a model already developed:
1. Proc logistic score statement
http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_logistic_sect066.htm
Include the data in your original proc logistic but use a new variable and ensure that the dependent variable is missing for the observations you want to predict.
data stacked;
set all;
if year >1950 then predicted=.;
else predicted=y;
run;
proc logistic data=stacked;
model predicted = factor1 - factor12;
output out=out_predicted predicted=p;
run;

how to find outliers in sas with proc means?

is there a way to detect an outlier from proc means while calculating min max Q1 and Q3?
the box plot procedure is not working on my SAS and I am trying to perform a boxplt in excel with the values from SAS.
Assuming you have a specific definition for what an outlier is, PROC UNIVARIATE can calculate the value that appears at that percentile using the PCTLPTS keyword on the OUTPUT statement. It also will identify extreme observations individually, so you can see the top few observations (if you have few enough observations that the number of extremes is likely to be <= 5).
The paper A SAS Application to Identify and Evaluate Outliers goes over a few of the ways you can look at outliers, including box plots and PROC UNIVARIATE, and includes some regression-based approaches as well.
If you want a 'standard boxplot' use the outbox= option in SAS to create the standard data set used for a box plot.
proc boxplot data=sashelp.class;
plot age*sex / outbox = xyz;
run;

Random effect Estimate in SAS

I have a panel data of firms (Panel specification: ID,Time) and trying to run Logit Random Effect model on this data in SAS where my binary (0,1) dependent variable is Def. This is the code that I am using:
PROC GLIMMIX DATA=mydata METHOD=QUAD(QPOINTS=21) NOCLPRINT;
CLASS ID;
MODEL Def (DESC) = VAR1 VAR2 VAR3 VAR4/SOLUTION DIST=BINARY LINK=LOGIT;
RANDOM INTERCEPT / SUBJECT=ID;
RUN;
When I run the code, in the output the only table that I get for the coefficient estimates is called: Solutions for Fixed Effects. My question is that where are the coefficient estimates for random effect? How can I get those estimates in output?
Thanks for your help in advance.
Sei
Just add a SOLUTION option to the RANDOM statement as well.
RANDOM INTERCEPT / SUBJECT=ID SOLUTION;