Date: Thu, 13 Jul 2000 13:17:57 +0200
Reply-To: Frank Poppe <Frank.Poppe@PWCONS.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Frank Poppe <Frank.Poppe@PWCONS.COM>
Organization: UUNET-NL (http://www.nl.uu.net)
Subject: Re: Help with plotting: y * x = z with different lines for w
Hi,
Interesting little problem.
You want a separate line for each site, so the syntax for the plot statement
has to be PLOT Y*X = SITE ;
But then you want the linetypes depending on the TYPE of SITE. That means
that SYMBOL statements have to generated specifying for each SITE the right
linetype. That can be done with some macrocode.
I did it the following way.
Comments are added to (try to) explain what is going on.
PROC SQL NoPrint ;
/* First I need the set of all SITE/TYPE combinations */
CREATE TABLE distinct AS SELECT distinct site , type FROM plotme ;
/* I will need a macro-var with the number of sites later on */
SELECT count ( site ) INTO :nsites FROM distinct ;
/* Now create a set of macro-vars specifying the TYPE for each SITE
Since GPLOT will order the values for SITE before linking them to
the SYMBOL's, I order them on SITE here too. */
SELECT left(put(type,4.)) INTO :type1 - :type99
FROM distinct
ORDER BY site
;
/* Specify the color and linetype for the different TYPEs in macro-var's.
If there are more types, just add col3, etc.
If you want to specify more attributes, add similar macro-var's, and
change the SYMBOL statement later on accordingly. */
%let col0 = black ;
%let col1 = red ;
%let lin0 = 1 ;
%let lin1 = 3 ;
/* Now a macro is defined which will produce a SYMBOL statement
for each SITE */
%MACRO symbols ;
%DO _i = 1 %to &nsites ;
/* The most difficult part is to get the macro-evaluation right.
In the end I want SAS to 'see' for site n the statement
SYMBOLn .... LINE=1 ... ;
or
SYMBOLn .... LINE=3 ... ;
LINE=0 or LINE=1 has to come from the evaluation of
LINE=&lin0 or LINE=&lin1
The 0 or 1 has to come from the TYPE of the SITE under consideration.
This again is a macro-var (TYPEn ):
LINE=&&LIN&TYPEn
The first ampersand is 'doubled' because otherwise we would specify the
concatenation of the macro-var's &LIN and &TYPEn.
Now the n has to come from &_I, so replace n in the above by &_I, and
again
double the ampersands already there
LINE=&&&&LIN&&TYPE&_I */
SYMBOL&_i interpol = join color = &&&&col&&type&_i repeat = 1 line =
&&&&lin&&type&_i ;
%END ;
%MEND ;
/* Execute the macro */
%symbols ;
goptions gsfname = tplot
dev = gif
colors = (black);
proc gplot data = plotme ;
plot dv * month = site;
run;
--
Frank Poppe
PW Consulting
SASŪ Software Expert Center
http://www.pwcons.com
Joel Winter <jpwinter@umsl.edu> wrote in message
news:396cbc91.21536688@news.umsl.edu...
> Hi all,
>
> I'm trying to plot means across time for 18 different sites. So my
> plot statement reads PLOT dv * month = site; I've heard this called a
> 'spaghetti plot' because there are so many tangled lines.
>
> There are two types of sites, so I would like to have a different line
> type (SYMBOL definition) for each type. I'm stumped on how to get
> this accomplished.
>
> I've tried changing the plot statement to PLOT dv * month = type, but
> mysterious extra lines show up in my plot. I'm really baffled at this
> seemingly simple problem. Any help or suggestions are appreciated.
>
> Here's the code which gets a spaghetti plot without the site type
> distinction:
>
> data plotme;
> input type site $ month dv;
> datalines;
> 0 5VIL 0 9.7723
> 0 5VIL 3 9.3441
> 0 5VIL 12 17.4500
> 0 AUTX 0 9.6566
> 0 AUTX 3 22.8889
> 0 AUTX 12 35.2500
> 0 CCPA 0 5.1900
> 0 CCPA 3 10.2738
> 0 CCPA 12 17.0333
> 0 DOWA 0 10.0294
> 0 DOWA 3 32.8082
> 0 DOWA 12 40.9647
> 0 HAVA 0 15.4902
> 0 HAVA 3 19.5053
> 0 HAVA 12 28.9583
> 0 KCMO 0 10.7843
> 0 KCMO 3 40.8202
> 0 KCMO 12 48.5467
> 0 NHCT 0 12.3267
> 0 NHCT 3 25.6667
> 0 NHCT 12 39.1591
> 0 SHKS 0 21.2165
> 0 SHKS 3 37.0920
> 0 SHKS 12 49.1625
> 0 WANC 0 8.0606
> 0 WANC 3 24.3947
> 0 WANC 12 33.3750
> 1 5RIL 0 10.4257
> 1 5RIL 3 11.0659
> 1 5RIL 12 22.9072
> 1 BPCT 0 8.6792
> 1 BPCT 3 19.1566
> 1 BPCT 12 30.1169
> 1 FWTX 0 9.8427
> 1 FWTX 3 27.7439
> 1 FWTX 12 44.9383
> 1 MENC 0 9.2471
> 1 MENC 3 10.7736
> 1 MENC 12 33.1806
> 1 RIVA 0 12.7619
> 1 RIVA 3 28.0000
> 1 RIVA 12 36.4557
> 1 SEKS 0 16.2063
> 1 SEKS 3 38.1690
> 1 SEKS 12 48.2937
> 1 SLMO 0 9.6214
> 1 SLMO 3 15.6374
> 1 SLMO 12 36.5930
> 1 UPWA 0 9.2588
> 1 UPWA 3 22.0870
> 1 UPWA 12 41.4921
> 1 WPPA 0 1.5347
> 1 WPPA 3 14.3855
> 1 WPPA 12 20.0952
> ;
>
> filename tplot 'c:\data\temp\tplot.gif';
> goptions gsfname = tplot
> dev = gif
> colors = (black);
> symbol i = join l = 3 repeat = 18;
> proc gplot gout = tplot;
> plot dv * month = site;
> run;
>