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

[using EG 9.4]

 

I have a data set that looks like this:

 

product sale_date   price 
abc     01/01/2018  1.13 
abc     06/01/2018  1.29 
abc     02/02/2018  1.23 
xyz     02/01/2018  1.54 
xyz     08/01/2018  1.58 
xyz     03/02/2018  1.41

And I need to plot two series (one for each product) on a pbspline plot of "price vs date".

 

I have tried a number of variations but am unable to get two separate series. Here's what I used most recently:

 

ods graphics on / height=600 width=900 noborder;
proc sgplot data=work.product_daily_sales(where=(product IN ('abc', 'xyz')));
by product;
pbspline x=sale_date y=price / legendlabel='company1' markerattrs=(symbol=circle color=blue size=5) lineattrs=(color=blue);
pbspline x=sale_date y=price /  legendlabel='company2' markerattrs=(symbol=circle color=red size=5) lineattrs=(color=red);
xaxis label='Date';
yaxis  label='US Price ($)';
title 'Sales Price by date of sale';
run;
quit;

Basically, I am comparing prices for a similar product to two different companies and I need to show the difference in pricing on the one graph.

 

The above code gets me closest to what I want but displays two graphs.

 

Can anyone help?

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
ods graphics on / height=600 width=900 noborder;
proc sgplot data=work.product_daily_sales(where=(product IN ('abc', 'xyz')));

pbspline x=sale_date y=price / group=product markerattrs=(symbol=circle color=blue size=5) lineattrs=(color=blue);
xaxis label='Date';
yaxis  label='US Price ($)';
title 'Sales Price by date of sale';
run;

@chuckd wrote:

[using EG 9.4]

 

I have a data set that looks like this:

 

product sale_date   price 
abc     01/01/2018  1.13 
abc     06/01/2018  1.29 
abc     02/02/2018  1.23 
xyz     02/01/2018  1.54 
xyz     08/01/2018  1.58 
xyz     03/02/2018  1.41

And I need to plot two series (one for each product) on a pbspline plot of "price vs date".

 

I have tried a number of variations but am unable to get two separate series. Here's what I used most recently:

 

ods graphics on / height=600 width=900 noborder;
proc sgplot data=work.product_daily_sales(where=(product IN ('abc', 'xyz')));
by product;
pbspline x=sale_date y=price / legendlabel='company1' markerattrs=(symbol=circle color=blue size=5) lineattrs=(color=blue);
pbspline x=sale_date y=price /  legendlabel='company2' markerattrs=(symbol=circle color=red size=5) lineattrs=(color=red);
xaxis label='Date';
yaxis  label='US Price ($)';
title 'Sales Price by date of sale';
run;
quit;

Basically, I am comparing prices for a similar product to two different companies and I need to show the difference in pricing on the one graph.

 

The above code gets me closest to what I want but displays two graphs.

 

Can anyone help?

 

Thanks in advance.


 

View solution in original post

5 REPLIES 5
Reeza
Super User
You don't want a BY statement. Instead what you want is a GROUP= option on the PBSPLINE statement that specifies PRODUCT as your GROUP variable.
Reeza
Super User
ods graphics on / height=600 width=900 noborder;
proc sgplot data=work.product_daily_sales(where=(product IN ('abc', 'xyz')));

pbspline x=sale_date y=price / group=product markerattrs=(symbol=circle color=blue size=5) lineattrs=(color=blue);
xaxis label='Date';
yaxis  label='US Price ($)';
title 'Sales Price by date of sale';
run;

@chuckd wrote:

[using EG 9.4]

 

I have a data set that looks like this:

 

product sale_date   price 
abc     01/01/2018  1.13 
abc     06/01/2018  1.29 
abc     02/02/2018  1.23 
xyz     02/01/2018  1.54 
xyz     08/01/2018  1.58 
xyz     03/02/2018  1.41

And I need to plot two series (one for each product) on a pbspline plot of "price vs date".

 

I have tried a number of variations but am unable to get two separate series. Here's what I used most recently:

 

ods graphics on / height=600 width=900 noborder;
proc sgplot data=work.product_daily_sales(where=(product IN ('abc', 'xyz')));
by product;
pbspline x=sale_date y=price / legendlabel='company1' markerattrs=(symbol=circle color=blue size=5) lineattrs=(color=blue);
pbspline x=sale_date y=price /  legendlabel='company2' markerattrs=(symbol=circle color=red size=5) lineattrs=(color=red);
xaxis label='Date';
yaxis  label='US Price ($)';
title 'Sales Price by date of sale';
run;
quit;

Basically, I am comparing prices for a similar product to two different companies and I need to show the difference in pricing on the one graph.

 

The above code gets me closest to what I want but displays two graphs.

 

Can anyone help?

 

Thanks in advance.


 

chuckd
Calcite | Level 5

Thanks. I was almost there.

 

In cases like this, how do you change the marker and line attributes of the different series (products in this case)? So they're both not in blue.

Reeza
Super User
You could list them in the STYLEATTRS statement but I prefer using a data attribute map. I just find it simpler and cleaner to deal with.

There's examples here:
https://documentation.sas.com/?docsetId=grstatproc&docsetTarget=n18szqcwir8q2nn10od9hhdh2ksj.htm&doc...
chuckd
Calcite | Level 5
OK. I read about them but wasn't too sure that's what I needed. Thanks for your help.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 3423 views
  • 1 like
  • 2 in conversation