Hi! I need help creating a demographics table for a small data set. Other posts I've seen either separate variables or are more complicated. I tried inserting the following but it did not run. Any help is appreciated. TIA!
%TABLEN (data=data, by=arm,
var=age gender race onset_age,
type=1 2 2 1, outdoc=~/ibm/example1.rtf);
| Group 1 | Group 2 |
Gender (n, %) - Female |
|
|
Race (n, %) - Alaskan/PI - Asian - Black/AA - Hispanic - NH White |
|
|
Current Age (mean, SD) |
|
|
Onset Age (mean, SD) |
|
|
data have;
set sashelp.heart;
run;
proc sql;
create table want as
select 1 as id1,'Gender (n, %)' as a,1 as id2,sex as b,1 as id3,status as c,
cats('(',count(*),',',put( 100*count(*)/(select count(*) from have where status=a.status) ,7.2) ,')' )as value length=20
from have as a
group by sex,status
union
select 2 as id1,'Race (n, %)' as a,2 as id2,bp_status as b,1 as id3,status as c,
cats('(',count(*),',',put( 100*count(*)/(select count(*) from have where status=a.status) ,7.2) ,')')as value length=20
from have as a
group by bp_status,status
union
select 3 as id1,'Current Age (mean, SD)' as a,3 as id2,"Current Age (mean, SD)" as b,1 as id3,status as c,
cats('(',put(mean(ageatstart),7.2),',',put(std(ageatstart),7.2),')' )as value length=20
from have
group by status
union
select 4 as id1,'Onset Age (mean, SD)' as a,4 as id2,"Onset Age (mean, SD)" as b,1 as id3,status as c,
cats('(',put(mean(AgeCHDdiag),7.2),',',put(std(AgeCHDdiag),7.2),')' )as value length=20
from have
group by status
;
quit;
ods rtf file='c:\temp\want.rtf' style=journal;
proc report data=want nowd style(header)={font_style=roman};
column id1 a id2 b value,c;
define id1/group noprint;
define a/group noprint;
define id2/group noprint;
define b/group '';
define c/across '';
define value/group '';
compute before a;
if find(lowcase(a),'age') then len=0;
else len=80;
line @1 a $varying80. len;
endcomp;
compute b;
if missing(_break_) and not find(lowcase(a),'age') then call define(_col_,'style','style={indent=0.25in}');
endcomp;
run;
ods rtf close;
"it did not run" does not provide even the minimal amount of information needed to diagnose the problem you have encountered. We don't even know the problem description.
Help us help you. Please start with showing the sas log generated when you submitted the program code.
You cannot call a macro until you have defined it. Either by running the code that creates the macro. Or by having the code file that makes the macro available in the location pointed to by the SASAUTOS option.
Hello @terrig164,
Most likely, you want to use JeffMeyers' %TABLEN macro. Its most recent source code appears to be the file tablen_05102022.sas, which can be downloaded from the SAS Communities Library article Demographic Table and Subgroup Summary Macro %TABLEN. After submitting that code in your SAS environment your macro call %TABLEN(data=... should work.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.