I am using proc phreg to fit a Cox regression on a dataset with time-varying covariates. I want to somehow output a dataset to excel where I can then generate the survival curve. I have no idea how to do this - do I use the survival
option in the baseline
statement?
As an aside, the reason I want to generate the curve in excel is because I want to superimpose some different plots onto the same graph.
I am using SAS 9.4 TS1M2.
You can request SAS to create a dataset from the plot data it uses for built in plots. You can use the ODS TRACE commands to find the name(s) of the objects. Here is an example using a data set you should have available and Proc Freq.
First turn on ODS graphics, set the trace option.
ods graphics on; ods trace on; proc freq data=sashelp.class; tables age /plots=freqplot; run; ods trace off; ods graphics off;
The TRACE generates output like this in the log, the names and details will change for each procedure.
Output Added: ------------- Name: OneWayFreqs Label: One-Way Frequencies Template: Base.Freq.OneWayFreqs Path: Freq.Table1.OneWayFreqs ------------- Output Added: ------------- Name: FreqPlot Label: Frequency Plot Template: Base.Freq.Graphics.OneWayFreqChart Path: Freq.Table1.OneWayFreqPlots.FreqPlot -------------
In this case it is pretty obvious only one plot object is created FREQPLOT.
So add an ODS OUTPUT statement, could appear immediately before the procedure or in the body of the procedure code such as:
ods graphics on; proc freq data=sashelp.class; tables age /plots=freqplot; ods output freqplot=work.freqplot; run; ods graphics off;
The data used to create the plot will appear in the WORK.FREQPLOT data set.
Depending on the procedure you may need to filter the data or modify it so look closely at any of your output. If there were two or more variables on the tables statement there will be values of TABLE in the output set for each variable.
And for most things if the other data is in SAS I would combine the data and use SGPLOT to overlay multiple plots. Especially if I were doing a large number of them.
You can request SAS to create a dataset from the plot data it uses for built in plots. You can use the ODS TRACE commands to find the name(s) of the objects. Here is an example using a data set you should have available and Proc Freq.
First turn on ODS graphics, set the trace option.
ods graphics on; ods trace on; proc freq data=sashelp.class; tables age /plots=freqplot; run; ods trace off; ods graphics off;
The TRACE generates output like this in the log, the names and details will change for each procedure.
Output Added: ------------- Name: OneWayFreqs Label: One-Way Frequencies Template: Base.Freq.OneWayFreqs Path: Freq.Table1.OneWayFreqs ------------- Output Added: ------------- Name: FreqPlot Label: Frequency Plot Template: Base.Freq.Graphics.OneWayFreqChart Path: Freq.Table1.OneWayFreqPlots.FreqPlot -------------
In this case it is pretty obvious only one plot object is created FREQPLOT.
So add an ODS OUTPUT statement, could appear immediately before the procedure or in the body of the procedure code such as:
ods graphics on; proc freq data=sashelp.class; tables age /plots=freqplot; ods output freqplot=work.freqplot; run; ods graphics off;
The data used to create the plot will appear in the WORK.FREQPLOT data set.
Depending on the procedure you may need to filter the data or modify it so look closely at any of your output. If there were two or more variables on the tables statement there will be values of TABLE in the output set for each variable.
And for most things if the other data is in SAS I would combine the data and use SGPLOT to overlay multiple plots. Especially if I were doing a large number of them.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.