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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 813 views
  • 0 likes
  • 3 in conversation