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.
Use: series x=month y=rate / group=store;
What if you use a group variable on your series plot statement.
Series x=month y=rate group=store / ...
Use: series x=month y=rate / group=store;
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
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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.