Hi,
I have data for a set of analytes and I want to create a scatter plot for each analyte.
I would like to have four plots (one plot from each of four analytes) per page in a pdf file.
When I use the code below it creates the plots that I want and it puts them in the right position on the page; however, it puts four plots of analyte 1 on page 1, four plots of analyte 2 on page 2, etc., etc.
After it puts the plot for the first analyte in position on the first page, how do I make it move to the plot for the next analyte for the next position on the first page?
Thanks,
fastb
%MACRO SGPLOT; %DO i=1 %TO &total;
ODS NORESULTS; ODS PDF STARTPAGE=NOW NOTOC STYLE=lit_range;
ODS GRAPHICS ON / ANTIALIASMAX=1400;
ODS LISTING STYLE=lit_range GPATH =
'C:\Corn.Literature.Ranges\QC Plots' IMAGE_DPI=300;
ODS PDF FILE="C:\Corn.Literature.Ranges\QC Plots\QC Plots.pdf"
BOOKMARKGEN = NO;
title;/*TITLE "&&CROP_TYPE&i& &&TISSUE_TYPE&i &&ANALYTE&i";*/
OPTIONS NODATE NONUMBER ORIENTATION=Portrait;
ODS LAYOUT START HEIGHT=11in WIDTH=8.5in;
ODS REGION COLUMN_SPAN=2 x=0.5in y=0.5in WIDTH=3.3in HEIGHT=3.3in;
PROC SGPLOT DATA=prepped_plots /*NOAUTOLEGEND NOCYCLEATTRS*/;
WHERE Matrix="&&Matrix&i" AND Category="&&Category&i" AND
ANALYTE="&&ANALYTE&i";
*BAND X=x UPPER=Upper_99pct_Tol_Int LOWER=Lower_99pct_Tol_Int / x2axis FILL
FILLATTRS=(COLOR=GRAYCC);
YAXIS label="&&unit&i&" /*min =0*/ OFFSETMIN = 0.08 OFFSETMAX = 0.08;
XAXIS DISPLAY=(noticks novalues nolabel) OFFSETMIN=0.05 OFFSETMAX=0.05;
TITLE1 HEIGHT = 10pt "&&matrix&i";
TITLE2 HEIGHT = 10pt "&&category&i";
TITLE3 HEIGHT = 10pt "&&analyte&i";
SCATTER x=result_name y=result / NOMISSINGGROUP MARKERATTRS=(SIZE=10px) GROUP = reference;
KEYLEGEND / location = outside position = right; RUN;
ODS REGION COLUMN_SPAN=2 x=4.25in y=0.5in WIDTH=3.3in HEIGHT=3.3in;
PROC SGPLOT DATA=prepped_plots /*NOAUTOLEGEND NOCYCLEATTRS*/;
WHERE Matrix="&&Matrix&i" AND Category="&&Category&i" AND
ANALYTE="&&ANALYTE&i";
*BAND X=x UPPER=Upper_99pct_Tol_Int LOWER=Lower_99pct_Tol_Int / x2axis FILL
FILLATTRS=(COLOR=GRAYCC);
YAXIS label="&&unit&i&" /*min =0*/ OFFSETMIN = 0.08 OFFSETMAX = 0.08;
XAXIS DISPLAY=(noticks novalues nolabel) OFFSETMIN=0.05 OFFSETMAX=0.05;
TITLE1 HEIGHT = 10pt "&&matrix&i";
TITLE2 HEIGHT = 10pt "&&category&i";
TITLE3 HEIGHT = 10pt "&&analyte&i";
SCATTER x=result_name y=result / NOMISSINGGROUP MARKERATTRS=(SIZE=10px) GROUP = reference;
KEYLEGEND / location = outside position = right; RUN;
ODS REGION COLUMN_SPAN=2 x=0.5in y=3.8in WIDTH=3.3in HEIGHT=3.3in;
PROC SGPLOT DATA=prepped_plots /*NOAUTOLEGEND NOCYCLEATTRS*/;
WHERE Matrix="&&Matrix&i" AND Category="&&Category&i" AND
ANALYTE="&&ANALYTE&i";
*BAND X=x UPPER=Upper_99pct_Tol_Int LOWER=Lower_99pct_Tol_Int / x2axis FILL
FILLATTRS=(COLOR=GRAYCC);
YAXIS label="&&unit&i&" /*min =0*/ OFFSETMIN = 0.08 OFFSETMAX = 0.08;
XAXIS DISPLAY=(noticks novalues nolabel) OFFSETMIN=0.05 OFFSETMAX=0.05;
TITLE1 HEIGHT = 10pt "&&matrix&i";
TITLE2 HEIGHT = 10pt "&&category&i";
TITLE3 HEIGHT = 10pt "&&analyte&i";
SCATTER x=result_name y=result / NOMISSINGGROUP MARKERATTRS=(SIZE=10px) GROUP = reference;
KEYLEGEND / location = outside position = right; RUN;
ODS REGION COLUMN_SPAN=2 x=4.25in y=3.8in WIDTH=3.3in HEIGHT=3.3in;
PROC SGPLOT DATA=prepped_plots /*NOAUTOLEGEND NOCYCLEATTRS*/;
WHERE Matrix="&&Matrix&i" AND Category="&&Category&i" AND
ANALYTE="&&ANALYTE&i";
*BAND X=x UPPER=Upper_99pct_Tol_Int LOWER=Lower_99pct_Tol_Int / x2axis FILL
FILLATTRS=(COLOR=GRAYCC);
YAXIS label="&&unit&i&" /*min =0*/ OFFSETMIN = 0.08 OFFSETMAX = 0.08;
XAXIS DISPLAY=(noticks novalues nolabel) OFFSETMIN=0.05 OFFSETMAX=0.05;
TITLE1 HEIGHT = 10pt "&&matrix&i";
TITLE2 HEIGHT = 10pt "&&category&i";
TITLE3 HEIGHT = 10pt "&&analyte&i";
SCATTER x=result_name y=result / NOMISSINGGROUP MARKERATTRS=(SIZE=10px) GROUP = reference;
KEYLEGEND / location = outside position = right; RUN;
ODS LAYOUT END; %END; %MEND SGPLOT; %SGPLOT;
ODS PDF CLOSE;
You have the exact same where clause:
WHERE Matrix="&&Matrix&i" AND Category="&&Category&i" AND
ANALYTE="&&ANALYTE&i";
for each plot. So you tend to get the same result.
If you are always doing this group of four then you maybe should be using &matrix1, &matrix2 &matrix3 and &matrix4 and the same for category and analyte.
Another approach may be to use SGPANEL and create one panel of graphs in a 2 rows by 2 columns layout with an appropriate panelby variable added to the data.
Hi,
Sorry, I can't even look at that code.
If you can provide some test data (form of a datastep), then could provide some code, but at a guess:
data _null_; set <your_data>; if _n_=1 then i=1; if i=1 then call execute('<put overall information per page here>'); call execute('<put region information here>'); call execute('<put splgot here>'); i=ifn(i=4,1,i+1); run;
This would use your dataset containing the pararmeters, which is a loop, and generate the code needed out - i is the incrementor for each of the four regions and region can be derived from that. Would make your life easier. Note the consistent casing, indetation, use of code editor ({i} above post window) etc.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.