Desktop productivity for business analysts and programmers

Input parameters from text file

Not applicable
Posts: 0

Input parameters from text file


Does any one know a way to retrieve a parameter from a text file so an EG job can use parameters and be scheduled to run overnight?

Posts: 9,423

Re: Input parameters from text file

Posted in reply to deleted_user
There are several ways to do what you want (pass parameters to a "batch" process). One way is to read your text file with SAS and then create global macro variables from what you find in the text file. For example, on my system, I have a file in c:\temp\wantreg.txt that looks like this:[pre]
Keep in mind that this is just a file that I made up and typed into Notepad. Now my "batch" program will need to follow this general flow:

1) read the file c:\temp\wantreg.txt
2) make global macro variables from the info in the file
3) use the macro variables in subsequent steps
4) invoke or schedule the "batch" program in a manner appropriate to my operating system and software configuration.
The program that I show below does the first 3 things, however, your program would probably be much longer.[pre]
** step 1 and step 2;
%global numobs wantreg;
data _null_;
infile 'c:\temp\wantreg.txt';
length parmstr $12;
input parmstr $;
if _n_ = 1 then do;
prt = scan(parmstr,2,'=');
call symput('numobs',trim(prt));
else if _n_ = 2 then do;
reg = scan(parmstr,2,'=');
call symput('wantreg',trim(reg));

** verify in log that correct parms were created;
%put ==> parms: numobs =&numobs wantreg =&wantreg;

** step 3 use parms;
** your step 3 will be much longer than this;
proc print noobs;
var region subsidiary product sales;
where region = "&wantreg";

This is really just an outline of the kind of program you really need to write. For one thing, the layout of your text file is probably different from the layout of the file that I created in Notepad -- so your step 1 could be significantly different. The heart of the program is the call symput statement, which turns a data step variable into a SAS macro variable. The two macro variables that I create are GLOBAL macro variables because of the %GLOBAL statement in the code. I took the easy way out and made my parameters in the text file as long strings -- the first one was for the number of obs and the second one was for the region to print. Since my strings had an '=' sign, I could use the scan function to get just the portion of the string after the equal sign. There are other ways to parse the string and other ways to set the macro variable names, I just show an easy method.

For another thing, I don't have any parameter validation or error checking in my code ... for example, what if wantreg.txt only had 1 line and not 2 lines of parameters?? What should happen?? Is there some default for region that I need to set?? OR, what if there's a region parameter, but the value for NUMOBS is ALL or 1000000 -- do I really want to let them print a million obs?? Are there limits that I need to impose on the parameters??

To check the parameters is going to require knowledge of how to use SAS macro variables, how to code macro %IF statements and how to use CALL SYMPUT and/or %LET statements.

There are even -other- ways to pass parameters to a "batch" job. For example, when you are invoking SAS in batch, you could use pass values into your program with -INITSTMT or -SYSPARM options. Some of those methods are described here:

Since you are using an EG job, you may have other issues to consider, such as where the text file is physically located, or how to modify your job so that the reading of the data file happens before the rest of the tasks are executed. In addition, you have to be sure that any macro programs or parameters that you use or create do not bump into any macro programs or parameters used by EG behind the scenes.

If you are using EG within the context of the Business Intelligence Platform, you may have other issues to deal with, such as having the parm file live on the server where your batch job will execute.

Your best bet might be to contact Tech Support for help with this question, as they can find out all about your system configuration and help you with this task in the most appropriate manner. To contact Tech Support, go to:

Good luck!
Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation