I would like to make a plot line from this table, but it fails, it shows that there are no such names. What am I doing wrong ?
POLICY_VINTAGE | POLICY_TODAY | POLICY_PRIOR |
2008-11 | 1 | 1 |
2010-01 | 3 | 3 |
2010-03 | 1 | 1 |
2010-05 | 1 | 1 |
2010-06 | 2 | 2 |
2010-07 | 1 | 1 |
2010-09 | 1 | 1 |
2010-11 | 1 | 1 |
2011-01 | 1 | 1 |
2011-03 | 1 | 1 |
My code :
proc sql;
create table diff as
select today.policy_vintage
, today.number_policy as POLICY_TODAY
, prior.number_policy as POLICY_PRIOR
, today.number_policy - prior.number_policy as DIFFRENCE
from policy_vintage_weekly today
LEFT JOIN
(select *
from _work.POLICY_VINTAGE_WEEKLY
where run_date < today()
having run_date = max(run_date)
) prior
ON today.policy_vintage = prior.policy_vintage
;
quit;
proc sgplot data=diff;
series x=today.policy_vintage y=POLICY_TODAY / markerattrs=(color=vligb symbol=circlefilled size=9)
lineattrs=(color=vligb thickness=2);
series x=today.policy_vintage y=POLICY_PRIOR / y2axis markerattrs=(color=salmon symbol=circlefilled size=9)
lineattrs=(color=salmon thickness=2);
run;
A long layout allows you to use BY:
data diff;
input policy_vintage :$7. policy_today policy_prior;
datalines;
2008-11 1 1
2010-01 3 3
2010-03 1 1
2010-05 1 1
2010-06 2 2
2010-07 1 1
2010-09 1 1
2010-11 1 1
2011-01 1 1
2011-03 1 1
;
proc transpose data=diff out=long;
by policy_vintage notsorted;
var policy_today policy_prior;
run;
proc sort data=long;
by _name_;
run;
proc sgplot data=long;
by _name_;
series x=policy_vintage y=col1 / markerattrs=(color=vligb symbol=circlefilled size=9)
lineattrs=(color=vligb thickness=2);
run;
From now on, when there are errors in the LOG, show us the ENTIRE log for this portion of your code. Do not tell us there are errors, SHOW US the LOG.
x=today.policy_vintage
There is no such variable as today.policy_vintage. Variable names never have dots in them.
Yes, you are right, I deleted the dot. Now this kind of thing appears to me.
policy_today shows which vertical bar in 2022. Although in the table both values start at the same time and go almost equally
I wish there were two lines. x =polciy_vintage y = count let's say
Runnng your code:
data diff;
input policy_vintage :$7. policy_today policy_prior;
datalines;
2008-11 1 1
2010-01 3 3
2010-03 1 1
2010-05 1 1
2010-06 2 2
2010-07 1 1
2010-09 1 1
2010-11 1 1
2011-01 1 1
2011-03 1 1
;
proc sgplot data=diff;
series x=policy_vintage y=POLICY_TODAY / markerattrs=(color=vligb symbol=circlefilled size=9)
lineattrs=(color=vligb thickness=2);
series x=policy_vintage y=POLICY_PRIOR / y2axis markerattrs=(color=salmon symbol=circlefilled size=9)
lineattrs=(color=salmon thickness=2);
run;
I get this:
The two plots overlay each other, as both series have identical data.
Thanks, yes i see now, is it chance to divide plot to panel like a below ?
A long layout allows you to use BY:
data diff;
input policy_vintage :$7. policy_today policy_prior;
datalines;
2008-11 1 1
2010-01 3 3
2010-03 1 1
2010-05 1 1
2010-06 2 2
2010-07 1 1
2010-09 1 1
2010-11 1 1
2011-01 1 1
2011-03 1 1
;
proc transpose data=diff out=long;
by policy_vintage notsorted;
var policy_today policy_prior;
run;
proc sort data=long;
by _name_;
run;
proc sgplot data=long;
by _name_;
series x=policy_vintage y=col1 / markerattrs=(color=vligb symbol=circlefilled size=9)
lineattrs=(color=vligb thickness=2);
run;
Have a look at SGPANEL:
proc sgpanel data=long;
panelby _name_;
series x=policy_vintage y=col1 / markerattrs=(color=vligb symbol=circlefilled size=9)
lineattrs=(color=vligb thickness=2);
run;
Thanks to @Rick_SAS for https://blogs.sas.com/content/iml/2011/08/12/side-by-side-bar-plots-in-sas-9-3.html that gave me the SGPANEL idea.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.