BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Gieorgie
Quartz | Level 8

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Gieorgie
Quartz | Level 8

Yes, you are right, I deleted the dot. Now this kind of thing appears to me.

Gieorgie_0-1635935728668.png

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

Gieorgie_0-1635937477283.png

 

 

Kurt_Bremser
Super User

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:

Unknown.png

The two plots overlay each other, as both series have identical data.

Gieorgie
Quartz | Level 8

Thanks, yes i see now, is it chance to divide plot to panel like a below ?

Gieorgie_0-1635940326423.png

 

Kurt_Bremser
Super User

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;
Gieorgie
Quartz | Level 8
Thanks but is chance to show two plot on panels like panel A for today panel B for prior
Kurt_Bremser
Super User

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.

sas-innovate-white.png

Special offer for SAS Communities members

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.

 

View the full agenda.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1494 views
  • 2 likes
  • 3 in conversation