BookmarkSubscribeRSS Feed
JessicaVan
Calcite | Level 5

I am using SAS 9.3, and using the following link as an example: SAS/STAT(R) 9.2 User's Guide, Second Edition.

Suppose that I have another variable, called status (say, negative and positive), is it possible to use different colors for the Output 92.3.4 Profiles over Treatments, i.e, those blue lines now will have colors based on status?  Thanks a lot!

3 REPLIES 3
djrisks
Barite | Level 11

Hello JessicaVan,

You can use the code below to get the plot that you're after. The code below rearranges the format of the data so that GTL can be used to plot the data.

The only word of caution is that it seems that you are going from a paired t-test to a general linear model (by including Status), and therefore you probably should use Proc GLM or Proc Mixed instead of Proc tTest when analysing your factors.

/* Creating paired relationship and dummy status */

data pressure2;
  set pressure;
  paired_id = _n_;
  if _n_ <= 6 then statusn = 1;
  else statusn = 2;
run;

/* Stacking the data */

proc transpose data = pressure2 out = pressure_trans;
  by paired_id statusn;
  var SBPbefore SBPafter;
run;

/* Calculating Mean Value */
proc sql;
  create table pressure_trans2 as
  select *, avg(col1) as means
  from pressure_trans
  group by _NAME_
  order by _NAME_ desc, statusn;
quit;


proc template;
define statgraph profiles;
   begingraph;

     discreteattrmap name="symbols" /; /* Creating Legend attributes */
       value "Negative" / lineattrs=(color=GraphData1:color); /* Negative maps to value 1 of StatusN because 1 is the first one */
       value "Positive" / lineattrs=(color=GraphData2:color);
     enddiscreteattrmap;

     layout overlay /xaxisopts=(type=discrete display=(line ticks tickvalues) offsetmin=autocompress offsetmax=
                     autocompress discreteopts=(tickvaluefitpolicy=rotate))
               yaxisopts = (display = (line ticks tickvalues)) y2axisopts =(display=(line ticks tickvalues));

    seriesplot x = _NAME_ y = col1 /  group = paired_id index = statusn datatransparency = 0.1 lineattrs = (pattern = 1); /* Using group = paired_id to obtain the seperate line for each subject */   
    seriesplot x = _NAME_ y = col1 / yaxis=y2 group = paired_id index = statusn datatransparency = 0.1 lineattrs = (pattern = 1); /* Displaying secondary axis */  

    seriesplot x = _NAME_ y = means / lineattrs=(pattern=GraphFit2:LineStyle color=black thickness=3);  /* Plot of the means */
    discretelegend "symbols" / type = line;
  endlayout;
   endgraph;
end;
run;

goptions reset = all; /* Getting rid of any previous titles and footnotes */
proc sgrender data = pressure_trans2 template = profiles ;
run;

JessicaVan
Calcite | Level 5

Hello


Thank you very much for the sample code. It works, but not exactly what I have hoped. I was really hoping that we can change the color more easily in SAS. Thank you for those cautious words too, I am fully aware of that; I can't say more, but the big boss just want to "see" it that way.  

djrisks
Barite | Level 11

That's fine JessicaVan.

I'm glad it helped. Yes, I believe it's not that easy because when using the paired option in Proc Ttest, is doesn't expect someone to use another variable.

I also looked into updating the pairedplot template, however it didn't seem like it was possible for the template to use another variable.

Do you need to use another color in your plots? If so, instead of using color=GraphData1:color and color=GraphData2:color, you could just use color=red or color = blue and so on.

Thanks.

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1471 views
  • 3 likes
  • 2 in conversation