proc format library=DST;
value birthgrp
low-<15='1'
15-35='2'
35<-high='3';
value deathgrp
low-<9='1'
9-12='2'
12<-high='3';
value popgrp
low-<45='1'
45-71='2'
71<-high='3';
run;
proc means data=DST.world2;
format birthrat birthgrp. deathgrp deathgrp. popurban popgrp. ;
class birthgrp popgrp deathgrp;(log显示ERROR: 变量 BIRTHGRP 没有找到。
ERROR: 变量 POPGRP 没有找到。应该怎么用FORMAT定义的变量?
var birthrat deathrat inf_mort;
output out=statx mean(birthrat deathrat inf_mort)=ma mb mc stderr(birthrat deathrat inf_mort)=sa sb sc
max(birthrat deathrat inf_mort)=maa mab mac min(birthrat deathrat inf_mort)=mia mib mic ;
run;
data stat1(drop= _type_ _freq_);
set stat1;
*format ma mb mc sa sb sc maa mab mac mia mib mic 3.;
attrib ma label="birthratemean" format=3. mb label="deathratemean" format=3. mc label="inf_mormean" format=3.
sa label="birthratestderr" format=3. sb label="deathratestderr" format=3. sc label="inf_morstderr" format=3.
maa label="birthratemax" format=3. mab label="deathratemax" format=3. mac label="inf_mormax" format=3.
mia label="birthratemin" format=3. mib label="deathratemin" format=3. mic label="inf_mormin" format=3. ;
run;
proc print data=stat1;
run;
原问题如下
在(4)
中的SAS
程序中添加新的proc means
过程步和output
语句,创建一个新的数据集stats1.
数据集stats1
必须包含birthrate
、deathrate
、inf_mort
三个变量的样本均值、均值的标准差、最大与最小值,并且根据分类变量birthgrp
和popgrp
分成的9
个样本分别计算。利用types
语句来确保统计量仅仅只是计算根据分类变量birthgrp
和popgrp
分成的样本,并将结果输出在procmeans
语句中,同时添加一个procformat
过程来定义这些分类变量的输出格式,打印出数据集stats1
,并对新的变量添加label
语句。