BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kingCobra
Obsidian | Level 7

Hi,

 

Please see the attached.

 

Obvious question - I need the values on X axis to be spread the entire axis equidistant. 

Here is my code 

 

 

%let colour = %str(red|green|blue);

proc sgplot data=final noautolegend;
	vbox aval / category=avisitn datalabel=usubjid boxwidth=1;

	%do i = 1 %to &n.;
		%let col&i = %scan(&colour,&i,'|');
		refline &&minref&i &&maxref&i / axis=y lineattrs=(pattern=shortdash color=&&col&i);
	%end;

	yaxis type=linear values=(&minval. to &maxval. by &byvar.) label=%sysfunc(compbl("&param."));
	xaxis type=linear values=(1 2 3 4 5 6 7) label="Visit";
run;

 

It seems there is something obvious that I'm missing here. Any help would be appreciated.

 

Thanks,

D

 

delete_boxplot.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

Somethings are not matching between the graph and the code you have.provided.  You have provided x-axis label of "Visit", but I don't see it on the axis.  Also, I assume the AVISITN values are from 1-7, but it it is not cleary what is causing the large offsets on left or right.  I suggest try setting xaxis offsetmin=0 offsetmax=0 to see if the axis stretches the full width.  If yes, you could put in the right fractional value to get what you want.  But, still it is not clear what is causing the offsets.

 

It would be easier to help if you send a program with built in (sample) data as part of the program.  Then we can try running your program.  Which SAS release do you have?

 

I ran this code and it worked for me.  I removed DataLabel=usubjid and the macro lines for reference lines.  Note I did get the "Visit" label on the x-axis.

 

data final;
  do avisitn=2, 6, 7;
    do j=1 to 100;
	  aval=100+80*ranuni(2);
	  output;
	end;
  end;
run;

proc sgplot data=final noautolegend;
vbox aval / category=avisitn  boxwidth=1  ;
xaxis type=linear values=(1 2 3 4 5 6 7) label="Visit" ;
run;

Box1.png

View solution in original post

12 REPLIES 12
PaigeMiller
Diamond | Level 26

Downloading of Microsoft Office documents is discouraged, as it is a security risk. So, I can't see the problem.

--
Paige Miller
kingCobra
Obsidian | Level 7

Can't paste the plot here. Don't know how to present the plot.

 

Main problem is - the values on x axis are concentrated near the centre, taking 1/3 of the total space on x axis. So the rest 2/3 are just empty. I want the values to be spread equally on the entire x axis

PaigeMiller
Diamond | Level 26

Attach plot as pdf file?

--
Paige Miller
Jay54
Meteorite | Level 14

Somethings are not matching between the graph and the code you have.provided.  You have provided x-axis label of "Visit", but I don't see it on the axis.  Also, I assume the AVISITN values are from 1-7, but it it is not cleary what is causing the large offsets on left or right.  I suggest try setting xaxis offsetmin=0 offsetmax=0 to see if the axis stretches the full width.  If yes, you could put in the right fractional value to get what you want.  But, still it is not clear what is causing the offsets.

 

It would be easier to help if you send a program with built in (sample) data as part of the program.  Then we can try running your program.  Which SAS release do you have?

 

I ran this code and it worked for me.  I removed DataLabel=usubjid and the macro lines for reference lines.  Note I did get the "Visit" label on the x-axis.

 

data final;
  do avisitn=2, 6, 7;
    do j=1 to 100;
	  aval=100+80*ranuni(2);
	  output;
	end;
  end;
run;

proc sgplot data=final noautolegend;
vbox aval / category=avisitn  boxwidth=1  ;
xaxis type=linear values=(1 2 3 4 5 6 7) label="Visit" ;
run;

Box1.png

kingCobra
Obsidian | Level 7

Hi Sanjay,

 

The label for x-axis and y-axis are not shown on the attached file as I copied the plot from a pdf output onto a MS word doc.

The AVISITN is from 1-7, yes. 

Without the macro lines for refline  and datalabel=usubjid, I'm getting the same plot as you have got.

 

My guess is the probably the refline statement is causing the problem but can't figure out why?

 

I'll try the offsetmin and offsetmax as you've suggested. If that doesn't work, I'll put a sample data with my code.

Jay54
Meteorite | Level 14

We can better help debug this if you include the full code, with all the macro variables and sample data so we can run the program to see the results.  If you have long usubjid data labels, they will contribute of offsets.  But I don't see any data labels either.

kingCobra
Obsidian | Level 7

Hi Sanjay,

 

The offsetmin/max = 0.1 worked. Thanks for that.

 

But I'm still unsure why the problem occured at the first place. So I ran my code without those options. Here is my code and output and attached is the data (sample) in pdf.

 

%macro labplot(paramcd = , minval = , maxval= , byvar= );

options mprint mlogic;

data adlb;
   set adam.adlb;
   where saffl = "Y" and aval ne . and paramcd = "%qupcase(&paramcd)";
   param = propcase(param);
   keep usubjid avisitn avisit paramcd param trtan aval anrlo anrhi;
run;

proc sort data = adlb out=final;
  by usubjid;
run;

proc sql noprint;
      select param
        into: param
        from final;

      select count(distinct anrlo)
	  into: n
         from final;

      select distinct anrlo
          into: minref1 - : minref%cmpres(&n.)
	  from final;

      select distinct anrhi
          into: maxref1 - : maxref%cmpres(&n.)
	  from final;
quit;

%let colour = %str(red|green|blue);

ods graphics on / reset=all imagefmt=png outputfmt=PNG border=off height=100% width=100% antialias=on imagename="hemoglobin";
   
   proc sgplot data=final noautolegend;
       vbox aval / category=avisitn datalabel=usubjid boxwidth=1;
	%do i = 1 %to &n.;
	     %let col&i = %scan(&colour,&i,'|');
            refline &&minref&i &&maxref&i / axis=y lineattrs=(pattern=shortdash color=&&col&i);
	%end;
      yaxis type=linear values=(&minval. to &maxval. by &byvar.) label=%sysfunc(compbl("&param."));
      xaxis type=linear values=(1 2 3 4 5 6 7) label="Visit" /*offsetmin=0.1 offsetmax=0.1*/;
   run;

ods graphics off;

%mend labplot;

%labplot(paramcd = HGB, minval=100, maxval=180, byvar=10);

hemoglobin.png

Jay54
Meteorite | Level 14

If you can send a simple program with built in data (like my example) that shows the problem, you have a better chance to get more help from the community.  With a program using macros and data in pdf, it is much harder to help debug the issue.

kingCobra
Obsidian | Level 7

Without using the macro, I'm getting what I want. It's only when I use the macro, the offset problem occurs. Anyway using offsetmin/max=0.1 solve my problem.

Thanks for the solution. I'll be mindful about the data while I ask question next time.

ballardw
Super User

Run the code with options MPRINT symbolgen;

compare the log of the run with the code you have that generated the desired graph  before you added any macro variables.

 

Did you by any chance generate an earlier version of the graph of OFFSETMAX on the XAXIS and not replace the actual output file for some reason such as open in another program to view the result?

 

You may want to look at your ODS Graphics options and ODS PDF.

 

 

Reeza
Super User
I've edited your post - added the code using a code box and formatted it, as well as embedded the image using the PHOTO option. You can attach images with the photo instead of attachments. JPG/PNG are accepted formats among others.
kingCobra
Obsidian | Level 7
Thanks

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 12 replies
  • 4386 views
  • 1 like
  • 5 in conversation