Looping Macro Variables

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

Looping Macro Variables

Hello,

I'm trying to write a macro loop and having a bit of trouble getting it to work properly.

I need the loop to scroll through several macro variables that I have named sequentially and create a data set for each.

Example:

%let File1 = 'c:/myfile'

%let File2 = 'c:/myfile2'

%let File3 = 'c:/myfile3'

%let Filecount = 3;

I wrote the code so that the loop will change the number of the macro variable but this is not working. I think its because I'm using two macro variables to call one macro variable.

%macro dowork;

%do X=1 %to &Filecount;

DATA Set&X.;

  LENGTH

  F1               $ 106;

  FORMAT

  F1               $CHAR106.;

  INFORMAT

  F1               $CHAR106.;

  INFILE Invoic(&file&X.)

  LRECL=106

  ENCODING="WLATIN1"

  TERMSTR=CRLF

  DLM='7F'x

  MISSOVER

  DSD;

  INPUT

  F1               : $CHAR106.;

RUN;

%end;

%mend;

How can I reference these variables?


Accepted Solutions
Solution
‎03-06-2013 09:59 AM
Super Contributor
Posts: 1,636

Re: Looping Macro Variables

try changing

INFILE Invoic(&file&X.)

to

INFILE Invoic(&&file&X.)

View solution in original post


All Replies
Solution
‎03-06-2013 09:59 AM
Super Contributor
Posts: 1,636

Re: Looping Macro Variables

try changing

INFILE Invoic(&file&X.)

to

INFILE Invoic(&&file&X.)

Contributor
Posts: 35

Re: Looping Macro Variables

This worked! Thank you!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 171 views
  • 0 likes
  • 2 in conversation