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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.