%macro grpprint(indata=,grpvar=);
/*grpvar would be assigned to the age1-*/
proc sql noprint;
select distinct &grpvar into : age1 - from &indata;
quit;
/*total equal the number of macro varible*/
%let total = &sqlobs;
/*write do loop according to the macro variable age1: age&sqlobs*/
/*obtain the subset dataset*/
%do i=1 %to &total;
proc sql noprint;
create table data&i as
select *
from &indata
where age = &&age&i;
quit;
/*use proc report:dataset is the subset dataset:do loop*/
options papersize=letter ps=max ls=max nofmterr nonumber nodate formchar='|_---|+|---+=|-/\<>*' missing=' ';
ods escapechar="@";
ods rtf file="report&i..rtf" style=rtftable; *bodytitle;
title j=c "There are &sqlobs observations in Age= &&age&i";
footnote j=c "page &sqlobs of &sqlobs";
pro