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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 1541 views
  • 1 like
  • 2 in conversation