Data visualization with SAS programming

Affixing variable to lines in graphs

Reply
New Contributor
Posts: 2

Affixing variable to lines in graphs

I am trying to create multiple graphs for mulptiple locations using a fixed data set.  Some variables that I am sorting by do not exisit for some locations, causing my line assignments to change from location to location.  Is there a way for SAS to assign a variable to a line, and if that variable does not exist, not use that line in the graph?  In otherwords, the variable and line relationship are constant, their appearance on the graph is dependent upon the presence of the variable. 

SAS Super FREQ
Posts: 3,406

Re: Affixing variable to lines in graphs

Some example data would help.

 

It sounds like you have a BY variable, but you also have multiple Y variables, some of which are missing for certain values of the BY variable. Perhaps you are trying to plot something like this:

proc sgplot;

by State;

series x=x y=Y1;

series x=x y=Y2;

run;

 

The better way to handle this is to conver the data from wide form to long form. See the article "Plotting multiple series: Transforming data from wide to long."  when the data are in long form, the BY-group levels can have different number of lines. The corresponding code might look like this:

 

proc sgplot;

by State;

series x=x y=value / group=ID;

run;

 

New Contributor
Posts: 2

Re: Affixing variable to lines in graphs

Your suggested code is in the format I am using.  My problem is that I have 9 potential ID's that I am including in the group=ID.  However, sometimes that ID is missing.  At that point, SAS is reassigning my line assignements to skip the missing ID.  I need the line assignments to remain fixed, and skip that particular line in my graph.  Can that be done?

 

SAS Super FREQ
Posts: 3,406

Re: Affixing variable to lines in graphs

Some example data would help.  

 

Perhaps you are referring to the choice of colors and line patterns that are assigned to each ID. In that case, read about discrete attribute maps:

SAS Super FREQ
Posts: 1,080

Re: Affixing variable to lines in graphs

The best way to do that is to use a Discrete Attributes Map.  This is a sas data set in which you can specify, by value, the attributes each classivication value should get.  So for Id=A, you can specify a color, symbol shape and line pattern. and so on.  Missing group values can be skipped by setting MISSING or MISSINGGROUP options.  Now, your id values will always retain their attributes.

 

See:  http://blogs.sas.com/content/graphicallyspeaking/2013/04/02/attribute-maps-1/

Ask a Question
Discussion stats
  • 4 replies
  • 119 views
  • 0 likes
  • 3 in conversation