BookmarkSubscribeRSS Feed
terrig164
Calcite | Level 5

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)

 

 

5 REPLIES 5
Ksharp
Super User
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;

Ksharp_0-1745912308641.png

 

mkeintz
PROC Star

"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.

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
terrig164
Calcite | Level 5
 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
WARNING: Apparent invocation of macro TABLEN not resolved.
68
69 %tablen(data=DiseaseData, by=arm,
_
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
70 var=age gender race onset_age,
71 type=1 2 2 1, outdoc=~/ibm/example1.rtf);
72
73 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
83
Tom
Super User Tom
Super User

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.

FreelanceReinh
Jade | Level 19

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.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

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.

 

Register now

What is ANOVA?

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.

Discussion stats
  • 5 replies
  • 582 views
  • 4 likes
  • 5 in conversation