Hi!
I have the files 123.txt, 456.txt and 789.txt and a program like this:
*******************************************************
...
%let n= 123.txt;
...
*******************************************************
And I need to replace with 456.txt and 789.txt, and run again.
I'm trying this:
*****************************************************
%macro mb(stg);
...
%let n= &stg..txt;
...
%mend;
%let gball="123 456 789";
%do %while (&k<=3);
%let gb=scan(&gball,&k);
%mb(&gb);
%let k=k+1;
%end;
*****************************************************
You can note that I'm not very expert with macro, so any comment is very usefull.
Thanks for yours answers!!
Your %do loop cannot be in open code, it can only work inside a macro.
You haven't stated exactly what the problem is with this code, so ... what is the problem?
What exactly is your question? It's not clear what you need help with here.
Example 1, 3, 4 may be helpful to you here:
If you're importing multiple text files that are all the same, see this post as well:
Last but not least, look at CALL EXECUTE for a simple way to call a macro multiple times.
I usually use a pipe to get the list of files into a data set, then use CALL EXECUTE to call the macro once for each file.
@mbas wrote:
Hi!
I have the files 123.txt, 456.txt and 789.txt and a program like this:
*******************************************************
...
%let n= 123.txt;
...
*******************************************************
And I need to replace with 456.txt and 789.txt, and run again.
I'm trying this:
*****************************************************
%macro mb(stg);
...
%let n= &stg..txt;
...
%mend;
%let gball="123 456 789";
%do %while (&k<=3);
%let gb=scan(&gball,&k);
%mb(&gb);
%let k=k+1;
%end;
*****************************************************
You can note that I'm not very expert with macro, so any comment is very usefull.
Thanks for yours answers!!
Besides needing a macro to use %DO, you also need to get rid of the quotes, and you need to use the macro function (%scan) instead of the DATA step function (scan). Macro language does not use quotes to identify strings of characters. In combination, the new macro might look like this:
%macro loop (gball=);
%local k;
%do k=1 %to %sysfunc(countw(&gball));
%mb (%scan(&gball, &k))
%end;
%mend loop;
Then call it with (for example):
%loop (gball=123 456 789)
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.