BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
maaneksehgal
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

1 REPLY 1
ballardw
Super User

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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 597 views
  • 1 like
  • 2 in conversation