BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

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?

Cheers
DW
1 REPLY 1
Cynthia_sas
SAS Super FREQ
Hi:
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]
numobs=10
reg=Asia
[/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));
end;
else if _n_ = 2 then do;
reg = scan(parmstr,2,'=');
call symput('wantreg',trim(reg));
end;
run;

** 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 data=sashelp.shoes(obs=&numobs) noobs;
var region subsidiary product sales;
where region = "&wantreg";
run;
[/pre]

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:
http://ourworld.compuserve.com/homepages/CJac/sysparm.htm
http://www.lexjansen.com/pharmasug/2002/proceed/coders/cc05.pdf
http://www.sconsig.com/sastips/tip00280.htm

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:
http://support.sas.com/ctx/supportform/index.jsp

Good luck!
cynthia

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1830 views
  • 0 likes
  • 2 in conversation