%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

该文章展示了一段SAS代码,它定义了一个名为%grpprint的宏,用于处理输入数据集(indata=sashelp.class)。宏首先根据指定的变量(grpvar=age)提取不同的年龄值,然后对每个年龄组创建子数据集,并使用Procreport生成详细的报告,包括体重和身高等信息。报告以RTF文件形式保存,每页显示特定年龄组的数据。
最低0.47元/天 解锁文章
3133





