我在SAS中创建了一个虚拟变量,如果两个国家都是EMU的成员,那么在任何给定年份中,该值变为1,否则在该年份为0。
emu1=0;
if country1 in ("AUT","BEL","FIN","FRA","DEU","IRL","ITA","NLD","PRT","ESP") and year>1998 then emu1=1;
if country1 in ("GRC") and year>2000 then emu1=1;
emu2=0;
if country2 in ("AUT","BEL","FIN","FRA","DEU","IRL","ITA","NLD","PRT","ESP") and year>1998 then emu2=1;
if country2 in ("GRC") and year>2000 then emu2=1;
emu=0;
if emu1=1 and emu2=1 then emu=1;
现在,我希望看到变量gdp1
的平均值,对于取值为emu=0
的国家/地区和取值为emu=1
的国家/地区。我该怎么做?
我知道我可以使用PROC MEANS:
PROC MEANS DATA=gravitydata mean MAXDEC=2;
VAR gdp1;
run;
但这显示了所有观察的平均值。
提前致谢。
答案 0 :(得分:2)
只需添加class
语句,即按指定变量分组。
PROC MEANS DATA=gravitydata mean MAXDEC=2;
CLASS emu;
VAR gdp1;
run;