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!
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;
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.
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..
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.