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

I have no problem to generate one line using Proc sgplot like this:

data graphdata;

  input month $ store $ rate;

  datalines;

  Jan store1 20

   Feb stroe1 25

  ;

run;

proc sgplot data=graphdata;

   series x=month y=rate/markers

                 break

                 lineattrs=(color=blue)

                 markerattrs=(symbol=circlefilled color=blue)

                 legendlabel='rates for store1';

   xaxis type=discrete grid label=' ';

   yaxis label= 'rate' grid values=(0 to 60 by 10);

run;

Above code generate a line for store1, with xaxis having month and yaxis with rates.

However, I have problem to try to generate multiple for multiple stores when my dataset has data for more than one stores, E.g. if my data is like this:

data graphdata;

  input month $ store $ rate;

  datalines;

  Jan store1 20

  Feb store1 25 

  Jan store2 30

  Feb store2 40 

  Jan store3 55

  Feb store3 45

  ;

run;

Thanks a lot in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

Use:  series x=month y=rate / group=store;

View solution in original post

4 REPLIES 4
ScottS_SAS
SAS Employee

What if you use a group variable on your series plot statement.

Series x=month y=rate group=store / ...

Jay54
Meteorite | Level 14

Use:  series x=month y=rate / group=store;

Fisher
Quartz | Level 8

Excellent! Thanks Sanjay. I had thought I need to add multiple series statement somehow.

BTW, this way the SAS will automatically assign the graph bagroud color, line types and colors. How can I customize them, such as changing the background color as white, and use only solid line? I tried goptions cback=white, but it didn't seems work.

Thanks

Jay54
Meteorite | Level 14

If your data is grouped (as it is, with different store names), then the group attributes come from the style.  Each series will use different attributes like color, pattern from GraphData1 - GraphDataN.  You can force all lines to be solid by setting the lineattrs option:

series x=month y=rate / group=store lineattrs=(pattern=solid);

Note, the attribute change is an override, so all the lines will now have solid pattern.  To change the colors, you will have to change the settings in the style, unless you have SAS 9.3.  In SAS 9.3, you can use an ATTRMAP to assign custom colors by store name.

If you have multiple response type data structure, where each store has its own column (below), then you will use multiple SERIES plot statements, one for each series.  In this case, you can assign the attributes for each series independently

data graphdata;
input month $ store1 store2 store3;
datalines;
Jan 20 25 30
Feb 20 35 40
;
run;

proc sgplot data=graphdata nocycleattrs;
  series x=month y=store1 / lineattrs=(color=blue);
  series x=month y=store2 / lineattrs=(color=red);
  run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 51065 views
  • 15 likes
  • 3 in conversation