0

I would like to define multiple macro variables in a data step. In this case I would like to create the variables &buffer1, &buffer2, &buffer3, &buffer4. The number of buffers is variable, so I am not able to hard code the creation of these variables.

Here is the data step and do loop I am currently using:

%let buffers = 4;
data buffer;
    do buffer_number = 1 to &buffers;
        buffer_queue = 0;
        buffer_index = 0;
        output;
    end;
run;

What I would like to do is add a line within the do loop like %let buffer_buffer_number = 0;. This obviously doesn't work, since it just creates the variable &buffer_buffer_number.Is there some way I can use the do loop index (buffer_number) to create the macro variables?

1 Answer 1

1

Try the call symput() subroutine.

call symput(catt("buffer_",buffer_number),0);

The first argument takes a string that contains the macro variable name. Here I use the CATT() function to concatenate the values into the string you want.

The second argument is the value to put into the macro variable.

Sign up to request clarification or add additional context in comments.

1 Comment

Use the newer call symputx() as it has more options and handles automatic conversion of numeric variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.