BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BayesBeatsFreqs
Calcite | Level 5

How to plot five variables using Proc SGplot and the Scatter statement(s)?

var1: x

var2: y

var3: group

var4: markerchar?

var5: ?

Ideally, I would like to vary the symbol, symbol size, and symbol color on each figure.  

I'm using 9.4, SAS/STAT 15.1.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

If you have 5 separate variables you can include 5 series statements and control the symbols/colours in the statement.

Example with two lines here

https://robslink.com/SAS/ods2/sct1_info.htm

 

Another option is discrete attribute maps, for each variable you'll specify the symbol, colour, thickness etc in a data set and then pass that to the procedure.

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n18szqcwir8q2nn10od9hhdh2ksj.htm

 


@BayesBeatsFreqs wrote:

How to plot five variables using Proc SGplot and the Scatter statement(s)?

var1: x

var2: y

var3: group

var4: markerchar?

var5: ?

Ideally, I would like to vary the symbol, symbol size, and symbol color on each figure.  

I'm using 9.4, SAS/STAT 15.1.


 

View solution in original post

9 REPLIES 9
Reeza
Super User

If you have 5 separate variables you can include 5 series statements and control the symbols/colours in the statement.

Example with two lines here

https://robslink.com/SAS/ods2/sct1_info.htm

 

Another option is discrete attribute maps, for each variable you'll specify the symbol, colour, thickness etc in a data set and then pass that to the procedure.

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n18szqcwir8q2nn10od9hhdh2ksj.htm

 


@BayesBeatsFreqs wrote:

How to plot five variables using Proc SGplot and the Scatter statement(s)?

var1: x

var2: y

var3: group

var4: markerchar?

var5: ?

Ideally, I would like to vary the symbol, symbol size, and symbol color on each figure.  

I'm using 9.4, SAS/STAT 15.1.


 

PaigeMiller
Diamond | Level 26

@BayesBeatsFreqs wrote:

How to plot five variables using Proc SGplot and the Scatter statement(s)?

var1: x

var2: y

var3: group

var4: markerchar?

var5: ?

Ideally, I would like to vary the symbol, symbol size, and symbol color on each figure.  

I'm using 9.4, SAS/STAT 15.1.


From this description, I don't really have a good idea of what the resulting plot would look like. I also don't know how "var5: ?" should be interpreted.

--
Paige Miller
BayesBeatsFreqs
Calcite | Level 5
var5 is just another variable. the question mark (?) indicates that I don't know what option in the scatter statement that would allow for a fifth variable on the figure.
ballardw
Super User

What is var5 supposed to be used for? A question mark doesn't provide much help.

 

By default the Value of group is used to assign Marker appearance but the option Markerchar=variable can be used. Example with a data set you should have.

proc sgplot data=sashelp.class;
   scatter x=height y=weight/ markerchar=name;
run;

If you have a Group variable such as:

proc sgplot data=sashelp.class;
   scatter x=height y=weight/group=age markerchar=name;
run;

the values of the group variable will set some marker attributes, mostly color but possibly size of text.

 

You should provide some explicit descriptions of exactly what you want to control and the rules involved.

The DATTRMAP optional data set can be used to address GROUP variable appearance which would include settings for markers such as marker size, symbol, color, transparency.

The DATTRMAP may be the best way to control consistency across multiple graphs.

BayesBeatsFreqs
Calcite | Level 5
Ok, more detail: var1 and var2 are continuous, and var3-var5 are categorical with lets say two levels each, so a total of eight groups. How to show all eight groups on one figure? Each variable (var3-var5) should be identified by one of the following: symbol, symbol size, symbol color.
Reeza
Super User
I'm sorry but that's not enough to provide more help if you require it. Can you show an example of your data and the plot you want then?
I'm not sure how you'd show all that information on a single plot.
If you cannot share your own data consider creating a sample plot in Excel using the sashelp.heart data set which has a few continuous and categorical variables.
BayesBeatsFreqs
Calcite | Level 5

Can't offer any more info.  It was just a general question prompted by something I read.  thanks.

PaigeMiller
Diamond | Level 26

How about six variables on one plot? Here's what has been called the best statistical plot ever made: a drawing of Napoleon's campaign into Russia in 1812. https://bigthink.com/strange-maps/229-vital-statistics-of-a-deadly-campaign-the-minard-map/

--
Paige Miller
ballardw
Super User

@BayesBeatsFreqs wrote:
Ok, more detail: var1 and var2 are continuous, and var3-var5 are categorical with lets say two levels each, so a total of eight groups. How to show all eight groups on one figure? Each variable (var3-var5) should be identified by one of the following: symbol, symbol size, symbol color.

Proc sgplot will allow multiple plots to overlay on a single graph. Mixing some types is limited and may require you to modify your data bit depending what type of display you want for categorical. To display Scatter, series or similar plots with "categorical" really depends on what you want as there are limits at to what can be displayed on a single plot together.

 

 

Show you need to show what you might want or perhaps wonder around here to look at examples with data and code from multiple procedures: https://support.sas.com/en/knowledge-base/graph-samples-gallery.html

 

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