sas macro loop to process

Reply
Contributor
Posts: 46

sas macro loop to process

Hello,

So I have this question about how to create a loop using macro.

There is a piece of code and I would like it t run 12 times with different start dates.

For example,

_N_

value

1

01Jan2012

2

01Feb2012

3

01Mar2012

.

.

.

.

.

.

.

.

12

01Dec2012

%fruitsales(01Jan2012);

%fruitsales(01Feb2012);

%fruitsales(01Mar2012);

.

.

.

%fruitsales(01Dec2012);

And so on and on,

How can I just make one piece of code and let it loop run from value.1 to value.12?

Thanks all for help!!

Super User
Posts: 10,476

Re: sas macro loop to process

If the value is in a dataset then look up Call Execute to call the macro the each value of the variable in the dataset.

If you dates are SAS date value and you are using a ddmmmyy format to display them, you will likely want to create an actual character variable with the value using Put to simplify the call execute syntax.

A basic stub example:

data _null_;

     set have;

     call execute ('%fruitsales('||value||')');

run;

Or the Call Execute could be within a do loop that sets value.

Ask a Question
Discussion stats
  • 1 reply
  • 173 views
  • 0 likes
  • 2 in conversation