I am using the code below to generate a series of plots with sgplot in a loop. The process doesn't generate any plots.
data _null_;
array veh_no[2] _temporary_ (3725:3726)
;
call execute('proc sql;');
do i=1 to dim(veh_no) while (veh_no(i) ne .);
call execute(cats('%nrstr(%rept_plot3xxx)(',veh_no(i),')'));
end;
call execute('quit;');
run;
%macro rept_plot3xxx(num);
proc sgplot data=DWM_Min_list_3xxx_psi;
title "&num scatter plot";
yaxis label= "psi";
scatter x=OCCUR_DATE y=DWM_TRUCK_1_PRESS_2_FDBK_8451;
scatter x=OCCUR_DATE y=DWM_TRUCK_2_PRESS_2_FDBK_8453;
where VEHICLE_NO = '&num' and
DWM_TRUCK_1_PRESS_2_FDBK_8451 between 0 and 25 and
DWM_TRUCK_2_PRESS_2_FDBK_8453 between 0 and 25
;
run;
%mend rept_plot3xxx;
Submit the following and then post your full log back please if it doesn't work. Note I replaced the single quotes with double quotes to allow the macro variable to resolve. It's a good practice to put your WHERE at the top of your PROC then its clear that your data is filtered somehwo.
options MPRINT SYMBOLGEN MLOGIC;
%macro rept_plot3xxx(num);
title "&num scatter plot";
proc sgplot data=DWM_Min_list_3xxx_psi;
where VEHICLE_NO = "&num" and DWM_TRUCK_1_PRESS_2_FDBK_8451 between 0 and 25 and DWM_TRUCK_2_PRESS_2_FDBK_8453 between 0 and 25 ;
yaxis label= "psi";
scatter x=OCCUR_DATE y=DWM_TRUCK_1_PRESS_2_FDBK_8451;
scatter x=OCCUR_DATE y=DWM_TRUCK_2_PRESS_2_FDBK_8453;
run;
%mend rept_plot3xxx;
%rept_plot3xxx (3725) ;
@capam wrote:
I am using the code below to generate a series of plots with sgplot in a loop. The process doesn't generate any plots.
Why not?
You need to call the macro after defining it.
Since your data _null_ step comes before the macro definition then when it executed you may not have had the macro to call. What does your LOG look like? I suspect, at least the first time, the you may have had messages about "Apparent invocation of macro rep_plot3xxx not resolved".
Or verify that you have values in this range in the data set DWM_Min_list_3xxx_psi:
where VEHICLE_NO = '&num' and
DWM_TRUCK_1_PRESS_2_FDBK_8451 between 0 and 25 and
DWM_TRUCK_2_PRESS_2_FDBK_8453 between 0 and 25
Does anything happen with
%rep_plot3xxx (3725) ?
And what is that quit statement doing? Sgplot doesn't require one.
Ballardw,
Thanks for the quick reply. I tried the following with no plot output.
%macro rept_plot3xxx(num);
proc sgplot data=DWM_Min_list_3xxx_psi;
title "&num scatter plot";
yaxis label= "psi";
scatter x=OCCUR_DATE y=DWM_TRUCK_1_PRESS_2_FDBK_8451;
scatter x=OCCUR_DATE y=DWM_TRUCK_2_PRESS_2_FDBK_8453;
where VEHICLE_NO = '&num' and
DWM_TRUCK_1_PRESS_2_FDBK_8451 between 0 and 25 and
DWM_TRUCK_2_PRESS_2_FDBK_8453 between 0 and 25
;
run;
%mend rept_plot3xxx;
%rept_plot3xxx (3725) ;
Submit the following and then post your full log back please if it doesn't work. Note I replaced the single quotes with double quotes to allow the macro variable to resolve. It's a good practice to put your WHERE at the top of your PROC then its clear that your data is filtered somehwo.
options MPRINT SYMBOLGEN MLOGIC;
%macro rept_plot3xxx(num);
title "&num scatter plot";
proc sgplot data=DWM_Min_list_3xxx_psi;
where VEHICLE_NO = "&num" and DWM_TRUCK_1_PRESS_2_FDBK_8451 between 0 and 25 and DWM_TRUCK_2_PRESS_2_FDBK_8453 between 0 and 25 ;
yaxis label= "psi";
scatter x=OCCUR_DATE y=DWM_TRUCK_1_PRESS_2_FDBK_8451;
scatter x=OCCUR_DATE y=DWM_TRUCK_2_PRESS_2_FDBK_8453;
run;
%mend rept_plot3xxx;
%rept_plot3xxx (3725) ;
I think the problem is in your WHERE clause. You have '&num', which will not resolve the macro variable. You need to use double quotes there, i.e. "&num".
Hope this helps!
Dan
Running the following code produces the plots..
proc sgplot data=DWM_Min_list_3xxx_psi;
title "3725 scatter plot";
yaxis label= "psi";
scatter x=OCCUR_DATE y=DWM_TRUCK_1_PRESS_2_FDBK_8451;
scatter x=OCCUR_DATE y=DWM_TRUCK_2_PRESS_2_FDBK_8453;
where VEHICLE_NO = '3725' and
DWM_TRUCK_1_PRESS_2_FDBK_8451 between 0 and 25 and
DWM_TRUCK_2_PRESS_2_FDBK_8453 between 0 and 25
;
run;
Macro variables DO NOT resolve within single quotes.
This allows the the processor to not resolve the & when it's needed for text.
proc sgplot data=DWM_Min_list_3xxx_psi;
title "&num scatter plot";
yaxis label= "psi";
scatter x=OCCUR_DATE y=DWM_TRUCK_1_PRESS_2_FDBK_8451;
scatter x=OCCUR_DATE y=DWM_TRUCK_2_PRESS_2_FDBK_8453;
where VEHICLE_NO ="&num" and
DWM_TRUCK_1_PRESS_2_FDBK_8451 between 0 and 25 and
DWM_TRUCK_2_PRESS_2_FDBK_8453 between 0 and 25
;
run;
You likely do not have values of '&num' in your data. "&num" to resolve the macro variable.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.