Data visualization with SAS programming

SGPLOT, uneven tick on x-axis

Reply
Occasional Contributor
Posts: 8

SGPLOT, uneven tick on x-axis

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

SAS Super FREQ
Posts: 862

Re: SGPLOT, uneven tick on x-axis

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

;

Valued Guide
Posts: 632

Re: SGPLOT, uneven tick on x-axis

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

Valued Guide
Posts: 2,149

Re: SGPLOT, uneven tick on x-axis

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

Valued Guide
Posts: 632

Re: SGPLOT, uneven tick on x-axis

Peter,

Yes the DISTINCT does imply order.

Post a Question
Discussion Stats
  • 4 replies
  • 424 views
  • 0 likes
  • 4 in conversation