BookmarkSubscribeRSS Feed
Derik007
Calcite | Level 5

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:

CityTime IntervallDegree of fulfilmentScore
AJan. 1620.01%10
AFeb 1624.00%10
AMrz 1628.00%10
AApr 1626.10%10
AMai 1625.20%10
AJun 1628.50%10
BJan. 1625.00%8
BFeb 1625.00%8
BMrz 1625.53%8
BApr 1627.00%8
BMai 1630.43%8
BJun 1631.32%8
CJan. 1618.40%9
CFeb 1619.00%9
CMrz 1620.56%9
CApr 1620.10%9
CMai 1622.00%9
CJun 1625.78%9
DJan. 1626.35%12
DFeb 1625.00%12
DMrz 1627.40%12
DApr 1628.50%12
DMai 1628.90%12
DJun 1631.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!

11 REPLIES 11
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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:

http://blogs.sas.com/content/graphicallyspeaking/

PeterClemmensen
Tourmaline | Level 20

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;

 

PeterClemmensen
Tourmaline | Level 20

You can of course do a lot of stuff to make the graph more presentable, but does this solve your problem?

Derik007
Calcite | Level 5

Thanks a lot to everybody.

 

@PeterClemmensen

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.

Reeza
Super User

@PeterClemmensen Was using sample data. In your code, replace the DATA = HAVE statement with your own dataset name instead of HAVE. 

 

 

 

PeterClemmensen
Tourmaline | Level 20

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)';
Derik007
Calcite | Level 5

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?

Derik007
Calcite | Level 5

No, this doesnt seem to be possible. Maybe there is a way to have the graph in SAS instead of JPG-file.

Jay54
Meteorite | Level 14

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".

Derik007
Calcite | Level 5

Sorry, I was talking ot the SAS Output.

Derik007
Calcite | Level 5

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..

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 11 replies
  • 3179 views
  • 0 likes
  • 5 in conversation