Hi All,
I am rather new to SAS but I have been reading here for a while. At the moment I am facing a problem: I want to create a line diagramm with multiple lines in SAS.
My SAS dataset looks like this:
City | Time Intervall | Degree of fulfilment | Score |
A | Jan. 16 | 20.01% | 10 |
A | Feb 16 | 24.00% | 10 |
A | Mrz 16 | 28.00% | 10 |
A | Apr 16 | 26.10% | 10 |
A | Mai 16 | 25.20% | 10 |
A | Jun 16 | 28.50% | 10 |
B | Jan. 16 | 25.00% | 8 |
B | Feb 16 | 25.00% | 8 |
B | Mrz 16 | 25.53% | 8 |
B | Apr 16 | 27.00% | 8 |
B | Mai 16 | 30.43% | 8 |
B | Jun 16 | 31.32% | 8 |
C | Jan. 16 | 18.40% | 9 |
C | Feb 16 | 19.00% | 9 |
C | Mrz 16 | 20.56% | 9 |
C | Apr 16 | 20.10% | 9 |
C | Mai 16 | 22.00% | 9 |
C | Jun 16 | 25.78% | 9 |
D | Jan. 16 | 26.35% | 12 |
D | Feb 16 | 25.00% | 12 |
D | Mrz 16 | 27.40% | 12 |
D | Apr 16 | 28.50% | 12 |
D | Mai 16 | 28.90% | 12 |
D | Jun 16 | 31.31% | 12 |
On the x axis there shouid be the time intervall and on the y axis the degreee of fulfilment (0 - 100%). I dont need the variable score. I want to have the different cities as lines in my diagram but this seems to be rather complicated in SAS. Does anyone have an idea how to do this?
Thanks in advance!
Should be very simple, shell code:
proc sgplot data=have; xaxis...; yaxis...; series x=time_interval y=fullfilment / group=city; run;
However I can't provide anything further than that - firstly you have not provided your test data as a datastep so I cannot tell if those are numeric values, dates etc. To get things in order on the axis you may need to apply a format to them and convert to number.
If you need any help on graphs I can recommend this site which has code examples of most graphs:
I've taken the liberty of rewriting a few of your Time Interval values.
Something Like this?
data have;
informat Time_Interval MONYY5.;
input City $ Time_Interval Degree_of_fulfilment Score;
format Time_Interval MONYY5.;
datalines;
A Jan16 20.01 10
A Feb16 24.00 10
A Mar16 28.00 10
A Apr16 26.10 10
A May16 25.20 10
A Jun16 28.50 10
B Jan16 25.00 8
B Feb16 25.00 8
B Mar16 25.53 8
B Apr16 27.00 8
B May16 30.43 8
B Jun16 31.32 8
C Jan16 18.40 9
C Feb16 19.00 9
C Mar16 20.56 9
C Apr16 20.10 9
C May16 22.00 9
C Jun16 25.78 9
D Jan16 26.35 12
D Feb16 25.00 12
D Mar16 27.40 12
D Apr16 28.50 12
D May16 28.90 12
D Jun16 31.31 12
;
proc sgplot data=have;
series x=time_interval y=Degree_of_fulfilment / group=city;
run;
You can of course do a lot of stuff to make the graph more presentable, but does this solve your problem?
Thanks a lot to everybody.
This comes close to what I want to have but my real dataset is a lot bigger, so I need to have a datastep without the writing the datalines. On the y axis I need a range from 0 to 100%. I hope you understand what I mean.
@PeterClemmensen Was using sample data. In your code, replace the DATA = HAVE statement with your own dataset name instead of HAVE.
What @Reeza said. And since your Degree_of_fulfilment is already represented in percentage terms, simply do this
yaxis min=0 max=100 label = 'Degree Of Fulfilment (Percent)';
Ok, thx a lot. I will try this.
I get a JPG-Output. Can I have the diagram in SAS too, so that I can export it to Excel?
No, this doesnt seem to be possible. Maybe there is a way to have the graph in SAS instead of JPG-file.
With SGPLOT, you can create industry standard output formats, such as PNG, PDF, etc. You can get a PNG output and include that in Excel workbook by using the ODS EXCEL destination. It is not clear what you mean by "graph in SAS file".
Sorry, I was talking ot the SAS Output.
I am having a diagram now but I would like to modify the line styles and the axis.
My code is:
title1 'Degree of fulfilment (in %)';
footnote1 height=2 angle=90 ' ';
proc sgplot data=have;
format time_interval ddmmyy10.;
series x=time_interval y=degree_of_fulfilment / group=city;
yaxis values=(0 to 100 by 10) valueshint display=(nolabel);
xaxis values=(20258 to 20748 by 14) valueshint display=(nolabel);
run;
However SAS doesnt adapt the axis although it should (SAS 9.2). I have been searching on the internet but it somehow doesnt work and I dont know why.
Is there also a way to choose the colors and forms of the lines in the diagram without writing a new code?
In SAS 9.4 there is the order keylegend but in SAS 9.2 it doesnt seems to be possible to change the location of the legend..
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.