BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Hello_there
Lapis Lazuli | Level 10

Hi, 

 

I'm trying to replicate this table.

Hello_there_0-1610202664219.png

PROC TABULATE data=data;
	class TREATMENT1 GENDER;
	table GENDER ALL, TREATMENT1 all;
	KEYLABEL ALL="Total";
	run;

Hello_there_1-1610203673276.png

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

 

1 ACCEPTED SOLUTION
4 REPLIES 4
Reeza
Super User
A 20 year old paper that's still valid and appropriate...one of the things that's nice about SAS.
Reeza
Super User

Your best bet:

https://communities.sas.com/t5/SAS-Communities-Library/Demographic-Table-and-Subgroup-Summary-Macro-...

 


@Hello_there wrote:

Hi, 

 

I'm trying to replicate this table.

Hello_there_0-1610202664219.png

PROC TABULATE data=data;
	class TREATMENT1 GENDER;
	table GENDER ALL, TREATMENT1 all;
	KEYLABEL ALL="Total";
	run;

Hello_there_1-1610203673276.png

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

 


 

Ksharp
Super User

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 1109 views
  • 1 like
  • 4 in conversation