11-09-2016 04:36 AM
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|
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!
11-09-2016 04:42 AM
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:
11-09-2016 05:37 AM
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;
11-09-2016 05:47 AM
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.
11-09-2016 06:37 AM
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)';
11-09-2016 07:56 AM
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".
11-10-2016 05:07 AM
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);
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..