PROC SQL
複数の連続したステートメントではなく、いくつかのコードを1つのステートメントに統合できるのではないかと思いますSQL
。
こことここで提供されているのと同様に、マクロを使用して、調査の同意日における参加者の年齢を計算しています。マクロの機能のトラブルシューティングを試み、 %sumマクロを使用して出生時の赤ちゃんの総体重をオンスで計算しました(これはうまく機能します...)。ただし、年齢を計算しようとすると、マクロは機能しません。
ただし、SQL
新しいステートメントで マクロを使用すると、正常に機能します。
以下のコードは機能します:
%macro months(somedate,birth);
intck('month',&birth,&somedate)
- (day(&somedate) < day(&birth))
%mend months;
%macro days(somedate,birth);
intck('day',&birth,&somedate)
- (day(&somedate) < day(&birth))
%mend days;
%macro sum(part1, part2);
&part1*16 + &part2
%mend sum;
********** bringing in data from outside tables ;
proc sql;
create table demos as
select x.*, infcondt2 as c_dt,
y.*, datepart(visitdt) as v_dt format date9. ,
datepart(birthdt) as b_dt format date9. ,
birthweightlbs as lbs,
birthweightoz as oz,
lbs*16 + oz as tot_oz,
%sum(lbs,oz) as tot_oz_m
from enrolled as x,
demographics as y
where x.center = y.center and x.id = y.id ;
quit;
********** calculating age in months and in days ;
proc sql;
create table demos2 as
select * ,
%months(c_dt, b_dt) as age_m ,
%days(c_dt, b_dt) as age_d
from demos;
quit;
********** creating age groupings by months: 0-3 and 3-6 ;
proc sql;
create table demos3 as
select * ,
case
when age_m le 3 then 1
when age_m le 6 and age_m gt 3 then 2
else 3
end as age_interval
from demos2;
quit;
それを単一のステートメントに統合する方法はありますか?何かのようなもの:
proc sql;
create table demos as
select x.*, infcondt2 as c_dt,
y.*, datepart(visitdt) as v_dt format date9. ,
datepart(birthdt) as b_dt format date9. ,
birthweightlbs as lbs,
birthweightoz as oz,
lbs*16 + oz as tot_oz,
%sum(lbs,oz) as tot_oz_m,
%months(c_dt, b_dt) as age_m,
%days(c_dt, b_dt) as age_d,
case
when age_m le 3 then 1
when age_m le 6 and age_m gt 3 then 2
else 3
end as age_interval
from enrolled as x,
demographics as y
where x.center = y.center and x.id = y.id ;
quit;