BookmarkSubscribeRSS Feed
sam_sas2
Obsidian | Level 7

Hi All,

 

I am currently trying to format my output tables in HTML of PROC LIFETEST. 

 

I am able to play around with the font, text size and alignment in side the table. But is there any way I can align the tables in the way I want to? I.e. Position them in different location in the HTML.

 

This is the code I have right now, 

 

/*TITME TO EVENT ANALYSIS: KAPLAN-MEIER ESTIMATE */

proc format;
value sexFmt
     1 = "male"
     2 = "female";
run;

data os;
format patid 10.;
format sex sexFmt.;
call streaminit(6875687);
do patid = 5213 to 9899;
     sex = rand("integer",1,2);
     event_fl = rand("integer",1,0);
     duration_months = rand("integer",6,120);
     output;
     end;
run;

%macro product_limit_template;

proc template;
source Stat.Lifetest.ProductLimitEstimates;
 define table Stat.Lifetest.ProductLimitEstimates;
    notes "Product-Limit Survival";
    column GrpNumVar GrpChrVar Timelist GenericTime Censor NumberAtRisk ObservedEvents Survival Failure StdErr Failed Left Freq
       GenericIDNumeric GenericIDCharacter;
    header h1;
 
    define h1;
       text "Product-Limit Survival Estimates";
       space = 1;
       spill_margin;
       first_panel;
    end;
    parent = Stat.Lifetest.ProductLimitEstimates0;
 end;
 
 define table Stat.Lifetest.ProductLimitEstimates0;
    notes "Survival and Cumulative Hazard";
    dynamic TimeNDec TimelistNDec NumWidth NumDec;
    column GrpNumVar GrpChrVar Timelist GenericTime Censor NumberAtRisk ObservedEvents Survival Failure StdErr CumHaz StdErrCumHaz
       Failed Left Freq Weight GenericIDNumeric GenericIDCharacter;
    header h1 h2 h3;
 
    define h1;
       text "Survival Function and Cumulative Hazard Rate";
       space = 1;
       spill_margin;
       first_panel;
       just=c;
    end;
 
    define h2;
       text "Product-Limit";
       start = Survival;
       end = StdErr;
       just=c;
    end;
 
    define h3;
       text "Nelson-Aalen";
       start = Cumhaz;
       end = StdErrCumhaz;
       just=c;
    end;
 
    define GrpNumVar;
       dynamic GrpVarLab;
       translate _val_=._ into "";
       label = GrpVarLab;
       id;
       generic;
    end;
 
    define GrpChrVar;
       dynamic GrpVarLab;
       label = GrpVarLab;
       id;
       generic;
    end;
 
    define Timelist;
    	define header t;
       		text "Timelist";
       		vjust=m;
       	end;
       header = t;
       just = c;
       format_width = 8;
       format_ndec = TimelistNDec;
       style = RowHeader;
       id;
	   justify=on;
    end;
 
    define GenericTime;
    	define header t;
    		text "Duration (&duration_type.)";
       		vjust=m;
       	end;
       header=t;
       format_width = 8;
       format_ndec = TimeNDec;
       just = c;
       space = 0;
       style = RowHeader;
       id;
       generic;
	   justify=on;
    end;
 
    define Censor;
       header = " ";
       translate
          _val_=1 into "*",
          _val_=0 into "",
          _val_=. into "";
       format = 1.0;
       id;
    end;
 
    define Survival;
    	define header t;
    		text "Survival";
    		vjust=m;
    	end;
       header = t;
       format = D8.;
       just = c;
	   justify=on;
    end;
 
    define Failure;
    	define header t;
       		text "Failure";
       		vjust=m;
       	end;
       header = t;
       format = D8.;
       just = c;
	   justify=on;
    end;
 
    define StdErr;
    	define header t;
       		text "Survival Standard Error";
       		vjust=m;
       	end;
       header=t;
       format = D8.;
       just = c;
	   justify=on;
    end;
 
    define CumHaz;
       header = ";Cumulative;Hazard;";
       format = D8.;
       just = c;
    end;
 
    define StdErrCumHaz;
       header = ";Cum Haz;Standard;Error";
       format = D8.;
       just = c;
    end;
 
    define Failed;
 
       define header t;
          text ";Number;Failed;";
          just = c;
       end;
       header = t;
       just = c;
       format_width = NumWidth;
       format_ndec = NumDec;
	   justify=on;
    end;
 
    define Left;
 
       define header t;
          text ";Number;Left;";
          just = c;
       end;
       header = t;
       just = c;
       format_width = NumWidth;
       format_ndec = NumDec;
	   justify=on;
    end;
 
    define NumberAtRisk;
 
       define header t;
          text ";Number;at Risk;";
          just = c;
          vjust= middle;
       end;
       header = t;
       just = c;
       format_width = NumWidth;
       format_ndec = NumDec;
    end;
 
    define ObservedEvents;
 
       define header t;
          text ";Observed;Events;";
          just = c;
       end;
       header = t;
       just = c;
       format_width = NumWidth;
       format_ndec = NumDec;
    end;
 
    define Freq;
       header = "Freq";
       format_width = NumWidth;
       format_ndec = NumDec;
    end;
 
    define Weight;
       header = "Weight";
       format = D8.;
    end;
 
    define GenericIDNumeric;
       format = BEST8.;
       generic;
       data_format_override;
    end;
 
    define GenericIDCharacter;
       generic;
    end;
    required_space = 5;
    col_space_max = 4;
    col_space_min = 1;
 end;
 
 define table Base.Template.Table;
 end;

run;

%mend product_limit_template;

%macro km_curve(data=, duration_variable=, event_variable=, censor_value=, 
		duration_type=, timelist=, graph_title=, x_axis_title=, y_axis_title=, 
		stratification_variable=, condition=1, km_curve_tag=);
			
	%product_limit_template;
	
	ods trace on/ listing;
	
	ods html path="/home/u48457160/OS_HTML/";
	ods escapechar="^";
	
	proc odstext;
		h "Time To Event Analysis- Kaplan Meier Estimate"/ style={font_size=10 textdecoration=underline};
	run;
	
	proc odstext;
		h "^S={leftmargin=0.25in} 1. What is Time To Event Analysis?"/ style={font_size=5};
		p 	"Time-to-event analysis is a branch of statistics that studies the amount of time it takes before a particular event occurs, say, 
		death, or failure of a component. Furthermore, the time to event can be measured in days, weeks, years, etc."/style={font_size=5};
		
		h "^S={leftmargin=0.25in} 2. What is Kaplan Meier Estimate?"/ style={font_size=5};
		p "Kaplan-Meier (KM) is non-parametric estimates of survival function that is commonly used to describe 
		survivorship of a study population and to compare two study populations. It is used to estimate and graph survival probabilities as a function of time"/style={font_size=5};
		
		h "^S={leftmargin=0.25in} 3. Vocabulary"/ style={font_size=5};
		
		p"a. Event: Outcome of interest, for e.g., death, disease occurrence etc ^n
			b. Observation time: The time until which a subject’s activities has been captured ^n
			c. Censoring: If a subject does not have an event during the observation time, they are censored (nothing is observed or known about that subject after the time of censoring) ^n
			d. Right censoring: This is done if a subject leaves the study before the event occurs ^n
			e. Left censoring: This is done if the event in interest happens before the start of the study ^n
			f. Interval censoring: This is done if they don’t know when exactly the event has occurred but know at what period it has occurred ^n
			g. Survival probability: It is also known as the survivor function S(t), is the probability that an individual survives from the time of origin to a specified future time t ^n
			h. Median survival: It is the point in time where half the patient population has survived ^n
			i. Mean survival: Mean KM estimates are calculated by finding the area under the KM curve
			 "/ style={font_size=5};
		
	run;
	
	title1 height=10 underlin=1 justify=left "^S={leftmargin=0.25in} Result Generation" ;
	title2 height=5 underlin=1 justify=left "^n ^S={leftmargin=0.25in} &graph_title." ;
	
	proc lifetest data=&data. method=km plots=survival(cb=hw test atrisk) 
			timelist=&timelist.;
		%if (&stratification_variable.) ne '' %then
			%do;
				strata &stratification_variable.;
			%end;
		time &duration_variable.*&event_variable.(&censor_value.);
		where &condition.;
		ods output quartiles=quartiles;
		ods output means=means;
		ods output censoredsummary=censoredsummary;
		ods output productlimitestimates=productlimitestimates;
	run;
		
	title1;
	title2;
	
	ods html close;
	
	ods trace off;
			
%mend km_curve;

%km_curve(data=os, duration_variable=duration_months, 
	event_variable=event_fl, censor_value=0, duration_type=months, timelist=12 24 
	36 48 60, graph_title=OS for All patients, x_axis_title=Time to Event (Month), 
	y_axis_title=Survival Prob, stratification_variable=, condition=, 
	km_curve_tag=);
1 REPLY 1

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 428 views
  • 0 likes
  • 2 in conversation