Is there a way to output at-risk numbers at specific time points to a file? With the following code, it outputs below the graph and I need to use something like PROC PRINT to view the data. Also it does not give heading on what the timepoints are. I need to share this with others and I am not satified with the way it is presented currently.
Here's a sample code-
data vagcan;
label days ='Days from Exposure to Death'
group ='Treatment Group';
input days @@;
censored = (days < 0);
days = abs(days);
if _n_ > 19 then group = 'pretrt1';
else group = 'pretrt2';
datalines;
143 164 188 188 190 192 206 209 213 216
220 227 230 234 246 265 304 -216 -244
142 156 163 198 205 232 232 233 233 233 233 239
240 261 280 280 296 296 323 -204 -344
;
PROC LIFETEST data=vagcan plots=survival(atrisk(outside(0.25))=150 160 180 300);
time days*censored(1);
strata Group;
run;
/*
As ballardw said, using ODS table to save these data.
*/
data vagcan;
label days ='Days from Exposure to Death'
group ='Treatment Group';
input days @@;
censored = (days < 0);
days = abs(days);
if _n_ > 19 then group = 'pretrt1';
else group = 'pretrt2';
datalines;
143 164 188 188 190 192 206 209 213 216
220 227 230 234 246 265 304 -216 -244
142 156 163 198 205 232 232 233 233 233 233 239
240 261 280 280 296 296 323 -204 -344
;
ods select none;
ods output SurvivalPlot=SurvivalPlot ;
PROC LIFETEST data=vagcan plots=survival(atrisk(outside(0.25))=150 160 180 300) ;
time days*censored(1);
strata Group;
run;
ods select all;
Timelist does not give at-risk numbers.
Timelist and ATRISK option gives identical results. I am running this on my real data and the numbers are off. Also on my real data, timelist gives a value of zero at the last time of followup while the ATRISK gives a number.
If you want something that appears in the results generally you can get that into a data set using ODS OUTPUT.
You use ODS TRACE to get a list of objects created by a procedure. Then use ODS OUTPUT statement(s) to place the output into a data set.
An example you can run:
ods trace on; proc freq data=sashelp.class ; tables sex * age / chisq ; run; ods trace off;
The Log will show after the code in addition to typical log output:
Output Added: ------------- Name: CrossTabFreqs Label: Cross-Tabular Freq Table Template: Base.Freq.CrossTabFreqs Path: Freq.Table1.CrossTabFreqs ------------- Output Added: ------------- Name: ChiSq Label: Chi-Square Tests Template: Base.Freq.ChiSq Path: Freq.Table1.ChiSq -------------
The important part for getting the objects into data sets is the NAME: and what follows.
To get the basic frequency information is the Crosstabfreqs and the Chi-Square tests then name is Chisq.
So this code will create data sets Mycrosstabset and Mychisquareset with the results.
ods output crosstabfreqs= mycrosstabset chisq = mychisquareset ; proc freq data=sashelp.class ; tables sex * age / chisq ; run;
If you are generating plots the objects will include the plots and you can capture data from them.
Caveat: some of these ODS OUTPUT generated data sets have quite a bit more than appears in the results window and may take some work to get pieces you want for other purposes.
/*
As ballardw said, using ODS table to save these data.
*/
data vagcan;
label days ='Days from Exposure to Death'
group ='Treatment Group';
input days @@;
censored = (days < 0);
days = abs(days);
if _n_ > 19 then group = 'pretrt1';
else group = 'pretrt2';
datalines;
143 164 188 188 190 192 206 209 213 216
220 227 230 234 246 265 304 -216 -244
142 156 163 198 205 232 232 233 233 233 233 239
240 261 280 280 296 296 323 -204 -344
;
ods select none;
ods output SurvivalPlot=SurvivalPlot ;
PROC LIFETEST data=vagcan plots=survival(atrisk(outside(0.25))=150 160 180 300) ;
time days*censored(1);
strata Group;
run;
ods select all;
@Ksharp Thank you so much. This is exactly what I was looking for!!!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.