BookmarkSubscribeRSS Feed
rjrobinjindal
Calcite | Level 5

Hi Everyone,

 

I would like to know how can I use something like a do loop inside proc sgplot (or any other plotting command used in SAS). The purpose is to make multiple series inside one single plot without explicitly naming the series inside proc sgplot statement. I want the user to be able to add the series himself outside proc sgplot so that the proc sgplot automatically gives the combined plot instead of specifically mentioning the series.

 

Normally we use this type of statement to print multiple series in SAS: 

 

proc sgplot data=test;
xaxis label= "x-axis";
yaxis label= "y-axis";
series x = x y=y1;
series x = x y=y2;
series x = x y=y3;
run;

 

I wish to have something like this:

 

%let y_list = y1 y2 y3;

 

proc sgplot data=test;
xaxis label= "x-axis";
yaxis label= "y-axis";

do for all values in y_list:

series x = x y= Step-by-step every element in y_list;
end;
run;

 

1 REPLY 1
Kurt_Bremser
Super User

Creating repeating code is one of the tasks you solve with macro programming:

%let y_list = y1 y2 y3;

%macro mymac(varlist);

proc sgplot data=test;
xaxis label= "x-axis";
yaxis label= "y-axis";

%do i = 1 %to %sysfunc(countw(&varlist.));

series x = x y= %scan(&varlist.,&i.);

%end;

run;

%mend mymac;

%mymac(&y_list)

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1393 views
  • 1 like
  • 2 in conversation