Hi All
I want to use SGPLOT to plot a uneven tick on x-axis in a proportional space but show all x value (see data below). how to do it? highly appreciate it for any suggestion.
x y
8 19
15 38.8
22 30.6
28 31
29 34.1
thanks!!
Muyi
This little example should work for you. Let me know if you have any questions about it.
Thanks!
Dan
data mydata;
input x y;
cards;
8 19
15 38.8
22 30.6
28 31
29 34.1
;
run;
data null;
set mydata end=eof;
call symput('val'||left(trim(_n_)), trim(left(x)));
if eof then call symput('tot',trim(left(_n_)));
run
;
%macro value;
%do i= 1 %to &tot;
&&val&i
%end;
%mend value;
proc sort data=mydata; by x;
run;
proc sgplot data=mydata noautolegend;
xaxis values=(%value);
needle y=y x=x;
series y=y x=x;
run
;
I would be tempted to replace the macro and the DATA step with a SQL step
proc sql noprint;
select distinct x
into :values separated by ' '
from mydata;
quit;
the XAXIS statement becomes:
xaxis values=(&values);
Dan the order of the values in the XAXIS statement does not seem to matter (I never noticed this before). Are there any issues with the values not being in order?
Message was edited by: Art Carpenter I left off the separated by phrase - added now
IArt
Does the DISTINCT impose order?
If not, muyi could extend the sql like:
Proc sql ;
Select distinct x
Into :values separated by ' '
from myData
ORDER BY x ;
peterC
Message was edited by: Peter Crawford Perhaps I should show the whole sql step
Peter,
Yes the DISTINCT does imply order.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.
Ready to level-up your skills? Choose your own adventure.