Hello.
X-AXIS of my spaghetti plot looks messy.
When I tried to define values manually (e.g.
COLAXIS LABEL="Days Post-Dose 1" VALUEATTRS=(SIZE=8) VALUES=(0 10 20 30 40 50 60 70 80 90 100);
) , or using other predefined, data driven-variable:
%LET values_str = 0;
%DO i = 10 %TO &max_ady %BY 10;
%LET values_str = &values_str &i;
%END;
COLAXIS LABEL="Days Post-Dose 1" VALUEATTRS=(SIZE=8) VALUES=(&values_str);
plot becomes empty
Can you please help me to fix the x-axis and make it readable.
Here is the requested representation:(up to max ady (which is 100 in this case))
Here is my code:
%MACRO mygraph;
PROC SGPANEL DATA= &dset_in. NOAUTOLEGEND;
FORMAT basecatn baseqctn. &PLOT_col_var trtpn. R2BASE ;
PANELBY basecatn / NOVARNAME NOHEADERBORDER BORDER HEADERATTRS=(WEIGHT=BOLD) LAYOUT=PANEL SPACING=5;
VLINE ady / RESPONSE=R2BASE GROUP=usubjid GROUPORDER=ASCENDING;
ROWAXIS LABEL="Fold-increase vs Day 1" VALUEATTRS=(SIZE=8) MIN=0 MAX=&max_aval;
COLAXIS LABEL="Days Post-Dose 1" VALUEATTRS=(SIZE=8);
RUN;
%MEND;
Thank you 🙂
VLINE is a CATEGORY plot. If the values on your colaxis statement values are not in the data then they are suppressed.
Use a different plot like SERIES if you have LOTS of x-axis values, especially if the values you have in the data are not exactly the same as in your desired Values list.
Here is an example with a different data set so the X axis values are not multiples of 10 but are numeric:
data have ; do group=1 to 4 ; do subjid=1 to 10 ; do x=1 to 100 by 7; y=subjid+x ; *or random value, or whatever ; output ; end ; end ; end ; run ; proc sgpanel data=have; title "Vline, Odd values on xaxis, default"; panelby group; vline x / response=y group=subjid; run; proc sgpanel data=have; title "Vline, Odd values on xaxis, Colaxis Values list"; panelby group; vline x / response=y group=subjid; colaxis values=(0 to 100 by 10); run; proc sgpanel data=have; title "Series, Odd values on xaxis, Colaxis Values list"; panelby group; series x=x y=y/ group=subjid; run; title;
I think that with some data sets it is best to sort the data by the Panelby variable(s), then the Group variable, then the X variable as Series may plot a bit differently.
Data.
Can't create or test graph code without data. Example data should be provided in the form of a working data step code pasted into a text box opened on the forum with the </> icon that appears above the main message window.
Typically the graph procedures will use values lists with an increment so not need to write macro loops for such:
values = (0 to 100 by 10)
if the values are dates you can specify by values like month or year so pretty neat.
Did you have working code for Ady before writing the macro?
Is Ady character or numeric? The behavior you describe with the either of the given value lists makes me suspect CHARACTER because if the values are not exactly as listed in the values then they would not appear. Also that ugly axis indicates that the values have been treated as discrete which is typically character values as SAS cannot "round" character values and provide nicer tick marks.
Run proc contents on your data set and show us the results.
Note that SGPANEL and VLINE don't complain if you give an apparent numeric colaxis value list with a character variable just don't get much of graph. Here are two examples that you should be able to run as you should have the Sashelp.cars data set.
The first is a pretty basic Sgpanel with a character vline. The second provides a values list and behaves like your code did when you provided a numeric list:
proc sgpanel data=sashelp.cars; title "No colaxis statement with character Vline"; panelby origin; vline type /response=msrp; run; proc sgpanel data=sashelp.cars; title "Numeric colaxis with character vline"; panelby origin; vline type /response=msrp; colaxis values=(0 to 100 by 10); run; title;
This data can't be produced with a single and simple data step unfortnately.
Here is the snippet of the input data.
Ady is representing days, it's numeric.
your provided exampe doesn't work(it creates the neccessary x-axis), and again, lead to a blank plot.
@webart999ARM wrote:
This data can't be produced with a single and simple data step unfortnately.
It might be hard to make that exact dataset, but you can make a similar dataset, something like (I'm not sure I've guessed correctly at your variable names):
data have ;
do basecatn=1 to 4 ;
do usubjid=1 to 10 ;
do ady=1 to 100 ;
R2base=usubjid+ady ;
output ;
end ;
end ;
end ;
run ;
When posting a question, it helps people help you if you either post code to make an example dataset that illustrates the problem, or use a sashelp dataset that we all have.
Also you want to post the simplest example of your problem that you can create, so for a question about graphing, you would want to post simple SGPANEL code, not a macro, since the macro language is not part of your question. And if you do make a sample dataset, it's good to give the variables simple names, to make the code easier for others to understand, e.g.:
data have ; do group=1 to 4 ; do subjid=1 to 10 ; do x=1 to 100 ; y=subjid+x ; *or random value, or whatever ; output ; end ; end ; end ; run ;
It's more work for you as the asker to write a simple example like that, but it will make it easier for others to help you. And often if you take the time to make a small example with minimal code, you'll solve the problem yourself before posting.
Thank you for your reply.
Yes, it works on the cars dataset, the same way it works on mine, but here there are no usubjids(the colorful lines iniside each quartile).
The main issue is that I am loosing that lines(see below), when I am trying to update x-axis vallues.
VLINE is a CATEGORY plot. If the values on your colaxis statement values are not in the data then they are suppressed.
Use a different plot like SERIES if you have LOTS of x-axis values, especially if the values you have in the data are not exactly the same as in your desired Values list.
Here is an example with a different data set so the X axis values are not multiples of 10 but are numeric:
data have ; do group=1 to 4 ; do subjid=1 to 10 ; do x=1 to 100 by 7; y=subjid+x ; *or random value, or whatever ; output ; end ; end ; end ; run ; proc sgpanel data=have; title "Vline, Odd values on xaxis, default"; panelby group; vline x / response=y group=subjid; run; proc sgpanel data=have; title "Vline, Odd values on xaxis, Colaxis Values list"; panelby group; vline x / response=y group=subjid; colaxis values=(0 to 100 by 10); run; proc sgpanel data=have; title "Series, Odd values on xaxis, Colaxis Values list"; panelby group; series x=x y=y/ group=subjid; run; title;
I think that with some data sets it is best to sort the data by the Panelby variable(s), then the Group variable, then the X variable as Series may plot a bit differently.
Thank you @Quentin and @ballardw for your inputs and suggestions regarding my issue and correct ways of quiestion publication in the forum 🙂
Using method proposed by @ballardw helped.
I have used SERIES plot:
series x=ady y=R2BASE / GROUP=usubjid GROUPORDER=ASCENDING;
along with the specified values for the x-axis:
values=(0 to 100 by 10);
and with some additional modifications(not related with the intial issue) got this result:
I have accepted @ballardw 's suggestion.
Thank you
Have a great weekend everyone.
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!
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.