BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Noomen
Fluorite | Level 6

Hi all,

I need 41 files from Y1980 to Y2020 with one variable (index) going from year*1000 to year*1000+900.

So for Y1980, Index will range from 19800000 to 19800900.

I wrote the following but the result is not as expected.

 

%macro myloop;
%do i=1980 %to 2020;
data Y&i;
%do index=&i*1000 %to &i*1000+900;
output;
%end;
run;
%end;

%mend;

 

%myloop;

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Looks like you are confusing macro and SAS code loops. Is this more like it?

%macro myloop;
%do i=1980 %to 2020;
data Y&i;
do index=&i*1000 to &i*1000+900;
output;
end;
run;
%end;

%mend;

 

%myloop;

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star

Looks like you are confusing macro and SAS code loops. Is this more like it?

%macro myloop;
%do i=1980 %to 2020;
data Y&i;
do index=&i*1000 to &i*1000+900;
output;
end;
run;
%end;

%mend;

 

%myloop;
Kurt_Bremser
Super User

The macro language is a code generator, and the code you created through it looks like this:

data Y1980;
output;
output;
output;
/* repeat 901 times all in all */
output;
run;

To create or manipulate data, you use the data step language, to create code, you use the macro language.

Macro variables (&index in your case) are only "visible" to the macro processor, not to the created code (unless you use them as parts of the created code).

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 628 views
  • 2 likes
  • 3 in conversation