BookmarkSubscribeRSS Feed
muyi
Calcite | Level 5

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

4 REPLIES 4
DanH_sas
SAS Super FREQ

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

;

ArtC
Rhodochrosite | Level 12

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

Peter_C
Rhodochrosite | Level 12

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

ArtC
Rhodochrosite | Level 12

Peter,

Yes the DISTINCT does imply order.

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1966 views
  • 0 likes
  • 4 in conversation