这是一个流行病学项目。我想计算 1961 年至 2013 年间不同人群的疾病频率:所有年龄段的男性、50 岁以上的男性和同样的两个女性病例。
首先,我导入了一个名为“pop_compl”的人口表,其中包含在上述时间跨度内男性(性别 = 1)和女性(性别 = 0,无冒犯)不同年龄段的人口数量。
然后,我使用 PROC SQL 在 SAS 中创建了空表:
proc sql;
create table m_rates (year num(10), population num(10), cases num(10), crude_incidence num(10), esr num(10), esr_95CI_ll num(10), esr_95CI_ul num(10));
create table m_rates_50plus (year num(10), population num(10), cases num(10), crude_incidence num(10), esr num(10), esr_95CI_ll num(10), esr_95CI_ul num(10));
create table w_rates (year num(10), population num(10), cases num(10), crude_incidence num(10), esr num(10), esr_95CI_ll num(10), esr_95CI_ul num(10));
create table w_rates_50plus (year num(10), population num(10), cases num(10), crude_incidence num(10), esr num(10), esr_95CI_ll num(10), esr_95CI_ul num(10));
现在,我想在上面的每个表格(以及后来的第三个“案例”)的前两列(年份和人口)中填充值,以便稍后在表格中计算所需的比率。列年份应填充值 1961-2013,列人口与 1961 年至 2013 年间每年的“pop_compl”中的相应人口数。
我想通过在宏和 do 循环中使用插入语句来做到这一点。看起来像这样:
%macro fill(table, sex, age_class);
insert into &table (year, population)
%do year=1961 %to 2013;
VALUES(&year, (select _&year from pop_compl where sex = &sex and age_class like "&age_class"))
%end;
;
%mend;
%fill(m_rates, 1, total);
%fill(m_rates_50plus, 1, > 50);
%fill(w_rates, 0, total);
%fill(w_rates_50plus, 0, > 50);
尽管这似乎在逻辑上是正确的,但 SAS 抱怨在 values 语句中使用查询 - 摘录:
1037 %fill(m_rates_50plus, 1, > 50);
NOTE: No rows were updated in WORK.M_RATES_50PLUS.
NOTE: Line generated by the invoked macro "FILL".
3 VALUES(&year, (select _&year from pop_compl where sex = &sex and age_class like
-
22
76
3 ! "&age_class"))
ERROR 22-322: Syntax error, expecting one of the following: a quoted string,
a numeric constant, a datetime constant, a missing value, ), +, ',', -, MISSING,
NULL, USER.
ERROR 76-322: Syntax error, statement will be ignored.
我尝试了几件事,更改了变量类型等等。没有任何帮助,我真的认为这是 SAS SQL 限制。我正在使用 SAS 9.2 32 位。目前,我不知道如何解决这个问题,也没有想出另一种快速的方法来做同样的事情。