Statistical programming, matrix languages, and more

A macro to activate a group of saved files in work library

Reply
Occasional Contributor
Posts: 5

A macro to activate a group of saved files in work library

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;

Grand Advisor
Posts: 17,464

Re: A macro to activate a group of saved files in work library

Macro variables have scope. It won't exist outside of the macro unless you've created it as a GLOBAL macro variable. 

Grand Advisor
Posts: 17,464

Re: A macro to activate a group of saved files in work library

Also, %include tick may not do what you want...not sure what values will be in there or what you're trying to do. 

Occasional Contributor
Posts: 5

Re: A macro to activate a group of saved files in work library

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.

 

Grand Advisor
Posts: 17,464

Re: A macro to activate a group of saved files in work library


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.

Grand Advisor
Posts: 9,596

Re: A macro to activate a group of saved files in work library

You don't need MACRO , Check this :

http://blogs.sas.com/content/iml/2015/11/02/search-all-variables.html

Grand Advisor
Posts: 17,464

Re: A macro to activate a group of saved files in work library

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. 

SAS Super FREQ
Posts: 3,420

Re: A macro to activate a group of saved files in work library

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;

 

Ask a Question
Discussion stats
  • 7 replies
  • 342 views
  • 0 likes
  • 4 in conversation