我试图绘制两组计算并随着时间的推移进行比较。 "队列"从原始表中的coh_asof_yyyymm派生的变量以数字格式存储在数据集中(2010年3月为201003)。现在,当我使用proc sgplot绘制它们时,四分之三的数据被挤在一起。如何更改此变量的格式以便产生x轴应该以间隔为单位的输出?
options nofmterr;
libname backtest "/retail/mortgage/consumer/new";
proc sql;
create table frst_cur as
select
coh_asof_yyyymm as cohort,
sum(annual_default_occurrence* wt)/sum(wt) as dr_ct,
sum(ScorePIT_PD_2013 * wt)/sum(wt) as pd_ct_pit,
sum(ScoreTTC_PD_2013 * wt)/sum(wt) as pd_ct_ttc
from backtest.sample_frst_cur_201312bkts
group by 1;
quit;
proc sgplot data = frst_cur;
series x = cohort y = pd_ct_pit;
series x = cohort y = pd_ct_ttc;
format cohort yyyyqc.;
xaxis label = 'Cohort Date';
yaxis label = 'Defaults';
title 'First Mortgage Current';
run;
答案 0 :(得分:1)
如果我说得对,我认为你的日期是一个数字而不是SAS日期。这并不罕见,人们将日期作为整数存储在他们的RDBMS表中,当SAS从表中导入数据时,它假定它是整数而不是日期。查看以下解决方案代码以供参考。
data testing_date_integer;
infile datalines missover;
input int_date 8.;
/* creating another variable which would be a SAS date, based on int_date.
we would be converting the integer date to charater and then append
day (01) to the charater and read using YYMMDD8. informat for SAS
to store the character as date
*/
sas_date=input(cats(put(int_date,8.),'01'),yymmdd8.);
format sas_date YYQ8.;
datalines4;
200008
200009
200010
200011
200012
200101
200102
200103
200104
200105
200106
;;;;
run;
proc print data=testing_date_integer;run;
如果以上代码显示并解决了您的问题,那么我建议您更新PROC SQL代码
proc sql;
create table frst_cur as
select
input(cats(put(coh_asof_yyyymm ,8.),'01'),yymmdd8.) as cohort,
.
.
.
此外,我建议更新PROC SGPLOT
中的同类群组的格式声明proc sgplot data = frst_cur;
.
.
format cohort yyq8.;
希望这能解决你的问题。
答案 1 :(得分:0)
data HAVE;
input DATE YYMMn6.;
format date YYQ8.;
datalines;
200008
200009
200010
200011
200012
200101
200102
200103
200104
200105
200106
;
run;
Proc Print Data=HAVE noobs; Run;
data HAVE2;
input coh_asof_yyyymm 8.;
datalines;
200008
200009
200010
200011
200012
200101
200102
200103
200104
200105
200106
;
run;
proc sql;
create table frst_cur as
select
input(put(coh_asof_yyyymm,6.),YYMMn6.) as cohort format=YYQ8.
From HAVE2;
Quit;