我已经搜索过,但是没有任何信息显示如何从行而不是列中给出的 数据绘制线形图。
我有这种形式的数据:
Firstname Lastname Sep Oct Nov Dec Jan Feb March April May June July
个人共有100行数据。我必须绘制从9月到7月开始的每个人的每个图表。我的输出将是100个单独的图。我知道如何绘制数据是否在列中,但这不是我所给的。更改数据将是太多的工作。我没有用于行的任何SAS代码:
**Proc sgplot data=data1;
series x=??? ( i need mths from Sep to July here)
Series y= ?? (will be the marks from the Sep to July)
Run;**
这是输出的外观:
答案 0 :(得分:0)
您的表格必须采用固定格式,例如:
FirstName LastName Date
John Smith 01JAN2018
Jane Doe 01JAN2018
这可以通过PROC TRANSPOSE.
完成,最好将日期与特定的年份/日期对齐。这将保持正确的日期顺序。假设您的数据适用于2018年。
创建示例数据
data have;
length name $10.;
array months[*] Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec;
retain goal 75;
do name = 'Mark', 'Jane', 'Jake', 'John', 'Jack', 'Jill', 'Bill', 'Jerry', 'Joseph';
do i = 1 to dim(months);
months[i] = round(100*rand('uniform') );
end;
output;
end;
drop i;
run;
解决方案
proc sort data=have;
by name goal;
run;
proc transpose data=have
out=have_transposed;
by name goal;
var Jan--Dec;
run;
data want;
set have_transposed;
Month = input(cats('01', _NAME_, 2018), DATE9.);
rename COL1 = Score;
format month monname3.;
drop _NAME_;
run;
proc sgplot data=want;
by name;
series x=month y=goal / name='goal' lineattrs=(color=salmon thickness=2);
series x=month y=score / name='series' lineattrs=(thickness=2);
scatter x=month y=score / markerattrs=(symbol=circlefilled) name='points';
keylegend 'series' 'goal';
run;