I am trying to write a piece of code that reads a number of files from a SAS library (named it: indexadd) and activate them in the work library. LIST contains the names of files to be transferred to the work environment. There are 253 saved files and I want to write a macro loop to go through the list and read and activate files one by one. This is what I have written. When I use print &Tick in IML section I can see that the correct names have been allocated to &Tick. E.g. ABB, NIM, ...
But, apparently in the second section my code fails to identify the correct names and I receive the following error message:
WARNING: Physical file does not exist.
ERROR: Cannot open %INCLUDE file TICK.
I appreciate any suggestion to tackle this problem.
Cheers.
data List; /*Activate List file*/
set Indexadd.List;
run;
%macro DataActivate; /* Creating a Macro Loop to activate files from Library*/
%do i=1 %to 253;
Proc IML;
use List;
read all var _char_ into List_Char;
mattrib List_Char colname={'Ticker'};
Tick=List_Char[&i,1];
%let Tick=%bquote(Tick);
print &Tick;
Quit;
data &Tick;
%include &Tick;
ticker = "&Tick";
run;
%END;
%mend;
%DataActivate run;
Macro variables have scope. It won't exist outside of the macro unless you've created it as a GLOBAL macro variable.
Also, %include tick may not do what you want...not sure what values will be in there or what you're trying to do.
Hi Reeza,
Thanks.
Do you have any suggestion how to fix the problem?
I have the files names in LIST and want to have a macro loop to go through the list, read a name and activate a saved file with that name.
@Reza wrote:
Hi Reeza,
Thanks.
Do you have any suggestion how to fix the problem?
I have the files names in LIST and want to have a macro loop to go through the list, read a name and activate a saved file with that name.
I don't know what activate a dataset means. If it's an IML term that's likely why.
You don't need MACRO , Check this : http://blogs.sas.com/content/iml/2015/11/02/search-all-variables.html
Not sure if this is applicable, but You can use PROC DATASETS to copy datasets from a library to the work library in one shot.
It is not clear to me what you are trying to accomplish. "Activate" is not a term I have ever heard. Do you mean "copy"? What is in the %INCLUDE file? Are the include files already created in the current working directory?
One thing is clear: you need to read the article "Macros and loops in the SAS/IML language." The article explains why you should use SYMPUT instead of %LET.
It is hard fo r me to recommend a solution when I don't understand what you are trying to accomplish, but let me suggest that you investigate rewriting the program to use the SUBMIT statement to pass in the parameter to the DATA step directly, as shown in the article "Passing values from PROC IML into SAS procedures."
The program might look something like this (untested):
Proc IML;
use List;
read all var _char_ into List_Char;
mattrib List_Char colname={'Ticker'};
do i=1 to 253;
Tick=List_Char[i,1];
submit Tick;
data &Tick;
%include "&Tick";
ticker = "&Tick";
run;
endsubmit;
end;
close List;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.