BookmarkSubscribeRSS Feed
Reza
Calcite | Level 5

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;

7 REPLIES 7
Reeza
Super User

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

Reeza
Super User

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

Reza
Calcite | Level 5

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.

 

Reeza
Super User

@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.

Ksharp
Super User
You don't need MACRO , Check this :

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

Reeza
Super User

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. 

Rick_SAS
SAS Super FREQ

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;

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 7 replies
  • 1008 views
  • 0 likes
  • 4 in conversation