BookmarkSubscribeRSS Feed
Jaime2
Obsidian | Level 7

Hi, 

I have a data set where essentially all variables are numeric and I would like to plot one variable (i.e., SScsem's listed below) as the y-variable and specify two other variables as the x-axis. The variables for the x-axis have a one-to-many relationship - one is a linear transformation of the other (the two scales have different properties so it would be best to use both for the x-axis).

My basic code is below (work-in-progress).

 

Any idea if SAS allows for this type of feature?

 

proc sgplot data=allCSEM;
series x=x y= SScsem_K0/LINEATTRS=(color=black) ;
series x=x y= SScsem_K02/LINEATTRS= (color=red);
series x=x y= SScsem_K03/LINEATTRS= (color=blue);
series x=x y= SScsem_K04/LINEATTRS= (color=green);
series x=x y= SScsem_K05/LINEATTRS= (color=orange);
series x=x y= SScsem_K06/LINEATTRS= (color=purple);
run;

7 REPLIES 7
WarrenKuhfeld
Ammonite | Level 13

Presumably you only want one displayed?  If so, why not just use that one?  You can use an X2 axis.  You don't have to display any ticks or anything.  If you want that perfect correspondence between the two axes, you have to resort to some trickery as I recall.  I know I have done that before with GTL.  I think I have done it with SGPLOT too.  Let me see if I can remember where.

Jaime2
Obsidian | Level 7

Thank you for your response but I would like both values for the x-axis displayed - each of which correspond to a variable in the data set. An example of what my data look like is below - maybe this helps clarify what I'd like.

 

x1  x2  y1 .... up to y8

1 118  .52

2 118  .53

3 119  .60

4 120  .62

5 120  .69

6 121  .78

7 121  .82

...

 

I'd need to be able to display both the x1 and x2 values along the x-axis. 

Jay54
Meteorite | Level 14

This should work.  Are you getting the graph you expect?  You could also use a GROUPED data structure, and then you need only one SERIES statement with GROUP option.

Jaime2
Obsidian | Level 7

My graph looks like what I want except I don't have the second x-axis that I need. I just briefly read the grouped option and I don't think I want to group my data. I'm not sure though. Do yo have an example? I explained my data structure a little better in a response above - perhaps that might help clarify what I'd like to achieve. 

DanH_sas
SAS Super FREQ

Try putting your second X variable in an XAXISTABLE and see if you get what you want.

WarrenKuhfeld
Ammonite | Level 13

I had not thought of using an X-axis table, but it sounds like @DanH_sas 's idea is right on target.

 

https://blogs.sas.com/content/graphicallyspeaking/?s=axis+tables

Jaime2
Obsidian | Level 7

I put my second x-axis variable (labeled "SS") in an xaxistable and it appears on the graph however, there are too many repeat values such that all the numeric values are blurred into one long incoherent string. Are there options such as "xaxis values=(118 to 132 by 2);" (as an example) that can be used with xaxistables? I cannot seem to format this secondary axis at all. My variables are all numeric, if that matters. 

 

I am not confident the xaxistable will solve this issue based on the limited number of option statements associated with it. 

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