Hi,
I'm trying to replicate this table.
PROC TABULATE data=data;
class TREATMENT1 GENDER;
table GENDER ALL, TREATMENT1 all;
KEYLABEL ALL="Total";
run;1. I need to have a fourth column that combines High and Low.
2. I also need to incorporate percents in the columns, so it equals N(%) for the categorical variable.
Thanks
Your best bet:
@Hello_there wrote:
Hi,
I'm trying to replicate this table.
PROC TABULATE data=data; class TREATMENT1 GENDER; table GENDER ALL, TREATMENT1 all; KEYLABEL ALL="Total"; run;
1. I need to have a fourth column that combines High and Low.
2. I also need to incorporate percents in the columns, so it equals N(%) for the categorical variable.
Thanks
PROC SQL. Here is an example.
%macro report_detail(dataset=,var=,time=);
/*For 第一个变量的 统计量*/
proc univariate data=&dataset(where=(time=&time)) outtable=temp_summary noprint;
class drug;
var &var ;
run;
/*For 第一个变量的 Geomean(CV)*/
ods select none;
ods output Equality=Temp_eq ConfLimits=Temp_ge TTests=Temp_tp;
proc ttest data=&dataset(where=(time=&time)) dist=lognormal;
class drug;
var &var;
run;
ods select all;
data Temp_ge_1;
set Temp_ge(where=(Method is missing));
drug=input(class, drug_ifmt.);
run;
proc sql;
create table temp_report_%sysfunc(translate(&time,_,.)) as
/*For 第一个变量的 N(Missing)*/
select &time as a,catx(' ',&time,'hr') as b length=10 ,1 as c,'N(Missing)' as d length=20,
drug as id format=drug_fmt.,
cats(_NOBS_,'(',_NMISS_,')') as value
from temp_summary
union
/*For 第一个变量的 Mean(SD)*/
select &time as a,catx(' ',&time,'hr') as b, 2 as c,'Mean(SD)' as d,
drug as id ,
cats(put(_MEAN_,10.4),'(',put(_STD_,10.4),')') as value
from temp_summary
union
/*For 第一个变量的 Median*/
select &time as a,catx(' ',&time,'hr') as b,3 as c,'Median' as d,
drug as id ,
put(_MEDIAN_,10.4 -l) as value
from temp_summary
union
/*For 第一个变量的 Q1,Q3*/
select &time as a,catx(' ',&time,'hr') as b,4 as c,'Q1,Q3' as d,
drug as id ,
cats(put(_q1_,10.4),',',put(_q3_,10.4)) as value
from temp_summary
union
/*For 第一个变量的 Min,Max*/
select &time as a,catx(' ',&time,'hr') as b,5 as c,'Min,Max' as d,
drug as id ,
cats(put(_MIN_,10.4),',',put(_MAX_,10.4)) as value
from temp_summary
union
/*For 第一个变量的 CV*/
select &time as a,catx(' ',&time,'hr') as b,6 as c,'CV' as d,
drug as id ,
put(_CV_/100,10.4 -l) as value
from temp_summary
union
/*For 第一个变量的 Geomean(CV)*/
select &time as a,catx(' ',&time,'hr') as b,7 as c,'Geomean(CV)' as d,
drug as id ,
cats(put(GeomMean,10.4),'(',put(CV,10.4),')') as value
from temp_ge_1
;
quit;
%mend report_detail;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.