我有结核病病例数据,其中包括以下变量:年龄,病例数,城市,年份,月份和过去11年(2006-2017)的种族。我想制作一个一年一行的线图,其中案例为y轴,月份为x轴,然后是每年的新行。但我不确定如何计算观察结果。我是sas的新人,所以如果我做错了,我会事先道歉,但这就是我的想法:
PROC SORT DATA= TB
BY YEAR;
RUN;
DATA YEAR;
SET TB;
COUNT + 1;
BY YEAR;
IF FIRST.YEAR THEN COUNT =1;
RUN;
PROC SGPLOT DATA = YEAR;
SERIES X = Month Y = COUNT;
SERIES X = Year Y = COUNT;
TITLE 'Temporal Patterns of TB from 2006-2017';
RUN;
但是我使用此代码得到一个空白输出。
非常感谢任何反馈/帮助! 提前谢谢!
答案 0 :(得分:1)
如果您提供样本数据,这会容易得多。假设您尝试执行类似于绘制折线图的操作,我将使用SASHELP.PRDSALE数据集作为演示。我在这里使用权重声明来累加金额但你不需要它。
首先运行PROC FREQ以获取摘要统计信息,然后使用SGPLOT中的输出来获取图表。您的SG代码已关闭。
proc freq data=sashelp.prdsale noprint;
table year*month / out=summary_stats;
weight actual;
run;
proc sgplot data=summary_stats;
series x=month y=count / group=year;
run;
答案 1 :(得分:0)
有各种各样的分组,副词或小组可以更好地沟通或更好地呈现每年的计数变化。
例如
data have (label="Disease cases");
do casedate = '01jan2006'd to '31dec2017'd;
year = year(casedate);
month = month(casedate);
do day_n = 1 to 30*ranuni(123);
case_status = floor(4*ranuni(123));
city_id = ceil(100*ranuni(123));
race = ceil(6*ranuni(123));
output;
end;
end;
run;
proc means noprint data=have;
class year month;
types year*month;
output out=counts n=freq;
run;
data counts;
set counts;
yearmo = mdy(month,1,year);
format yearmo yymmd7.;
run;
options orientation=landscape papersize=a4;
ods html close;
ods html;
proc sgplot data=counts;
series x=month y=freq / group=year;
xaxis type=discrete;
where _type_ = 3;
run;
proc sgplot data=counts;
series x=yearmo y=freq / group=year;
xaxis type=discrete display=(novalues);
where _type_ = 3;
run;
proc sgplot data=counts;
by year;
series x=yearmo y=freq / group=year;
xaxis type=discrete ;
where _type_ = 3;
run;
proc sgpanel data=counts;
panelby year;
series x=month y=freq ;
colaxis type=discrete;
where _type_ = 3;
run;
proc sgpanel data=counts;
panelby year / columns=4 ;
series x=month y=freq ;
colaxis type=discrete display=(novalues);
where _type_ = 3;
run;