Data visualization with SAS programming

Does SAS allow for two numeric variables to define x-axis?

Reply
Occasional Contributor
Posts: 9

Does SAS allow for two numeric variables to define x-axis?

[ Edited ]

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;

SAS Super FREQ
Posts: 496

Re: Does SAS allow for two numeric variables to define x-axis?

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.

Occasional Contributor
Posts: 9

Re: Does SAS allow for two numeric variables to define x-axis?

[ Edited ]
Posted in reply to WarrenKuhfeld

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. 

SAS Super FREQ
Posts: 1,265

Re: Does SAS allow for two numeric variables to define x-axis?

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.

Occasional Contributor
Posts: 9

Re: Does SAS allow for two numeric variables to define x-axis?

Posted in reply to Sanjay_SAS

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. 

SAS Super FREQ
Posts: 1,046

Re: Does SAS allow for two numeric variables to define x-axis?

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

SAS Super FREQ
Posts: 496

Re: Does SAS allow for two numeric variables to define x-axis?

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

Occasional Contributor
Posts: 9

Re: Does SAS allow for two numeric variables to define x-axis?

Posted in reply to WarrenKuhfeld

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. 

Ask a Question
Discussion stats
  • 7 replies
  • 158 views
  • 0 likes
  • 4 in conversation