SAS Macro : A Dynamic %Do Loop

Live Online Training : SAS Programming with 50+ Case Studies

- Explain Programming Concepts in Simple English
- Live Projects
- Scenario Based Questions
- Job Placement Assistance
- Get 20% off till July 14, 2017

Suppose you need to pass a variable in loop based on the input defined in a macro.
%macro report (input=, var = , class=);
%let n=%sysfunc(countw(&var));
%do i=1 %to &n;
%let val = %scan(&var,&i);
proc means data = &input noprint nway;
class &class;
vars &val;
output out=out&i mean= median= / autoname;
run;
%end;
%mend;

options mprint;
%report(input= test, var = b c, class=a);

When you execute the above sas program, it generates the following statements :

proc means data = &input noprint nway;
class a;
vars b;
output out=out1 mean= median= / autoname;
run;

proc means data = &input noprint nway;
class a;
vars c;
output out=out2 mean= median= / autoname;
run;

SAS Tutorials : 100 Free SAS Tutorials

About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has close to 7 years of experience in data science and predictive modeling. During his tenure, he has worked with global clients in various domains like retail and commercial banking, Telecom, HR and Automotive.


While I love having friends who agree, I only learn from those who don't.

Let's Get Connected: Email | LinkedIn

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*

Related Posts:

0 Response to "SAS Macro : A Dynamic %Do Loop"

Post a Comment

Next → ← Prev