BookmarkSubscribeRSS Feed
still_learning
Calcite | Level 5

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. 

4 REPLIES 4
Rick_SAS
SAS Super FREQ

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;

 

still_learning
Calcite | Level 5

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?

 

Rick_SAS
SAS Super FREQ

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:

Jay54
Meteorite | Level 14

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/

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
  • 4 replies
  • 1045 views
  • 0 likes
  • 3 in conversation