Help using Base SAS procedures

Specifying/Reading command line arguments for a SAS program

Reply
N/A
Posts: 0

Specifying/Reading command line arguments for a SAS program

Hi All,

How do we specify command line arguments to a SAS program and how to read the value of passed arguments in the SAS program.

Can someone explain please.

Thanks,
Neelam
Super Contributor
Posts: 474

Re: Specifying/Reading command line arguments for a SAS program

Posted in reply to deleted_user
Hello Neelam.

Have you checked the SYSPARM command line option?

It allows you to pass a string to the SAS session through a command line option.

See documentation here:
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a000543608.htm

Cheers from Portugal.

Daniel Santos @ www.cgd.pt.
N/A
Posts: 0

Re: Specifying/Reading command line arguments for a SAS program

Posted in reply to DanielSantos
Thanks Daniel.

Will check the documentation.
Super Contributor
Super Contributor
Posts: 3,174

Re: Specifying/Reading command line arguments for a SAS program

Posted in reply to deleted_user
Can you explain what a "command line arguments" represents to you? Also, the SYSPARM= invocation paramter allows you to pass a data-string to a SAS program for access when processing. Have a look at the SAS documentation and/or the SAS support website at http://support.sas.com/ for details about specifying and using SAS CONFIG/OPTIONS parameter SYSPARM= for your SAS application.

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Specifying/Reading command line arguments for a SAS program

Thanks Scott.

Will refer to the links.
N/A
Posts: 0

Re: Specifying/Reading command line arguments for a SAS program

Posted in reply to deleted_user
Hi,

I figured out how to use SYSPARM to read one parameter passed to a SAS program

I have the following in my .bat file
---------------------------------------------------------------------------------------------
set program_path="C:\DAG\SAS\Tests\sampleProgWithDiffDSWk.sas"
set folder_path="C:\DAG\SAS\Tests"

"C:\Program Files\SAS\SASFoundation\9.2\sas.exe" -SYSPARM %folder_path%
-SYSIN %program_path%

----------------------------------------------------------------------------------------------
Now, if I have to pass another argument to the SAS program(say parameter file_ext=".sas7bat"), do I have to concatenate with the previous parameter string and then parse in the SAS program or is there any way to pass multiple parameters?

Thanks,
Neel
Super Contributor
Super Contributor
Posts: 3,174

Re: Specifying/Reading command line arguments for a SAS program

Posted in reply to deleted_user
Yes, either using &SYSPARM with macro language or using a DATA step and using either my_sysparm_value="&SYSPARM" or the function SYSPARM(). Then your SAS application program must decide how to parse and use this information. If you intend to use the SYSPARM information as SAS code, you will want to parse &SYSPARM and then resolve additional (substring) SAS code using macro variables.

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Specifying/Reading command line arguments for a SAS program

Thanks Scott.
Super Contributor
Posts: 474

Re: Specifying/Reading command line arguments for a SAS program

Posted in reply to deleted_user
I see you have already found your way, but I just remembered another handy feature of SAS that might help you if you need to pass some large string to a SAS program.

SYSGET function will retrieve the value of any operating environment variable.

Don't know, might be handy.

Check the online documentation:
http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000245954.htm

Cheers from Portugual.

Daniel Santos @ www.cgd.pt.
N/A
Posts: 0

Re: Specifying/Reading command line arguments for a SAS program

Posted in reply to deleted_user
I am having some problem passing a string and parsing it in the SAS program.

I have a macro given below with signature

%macro findMatches (dir,pattern);

I invoke it as - With (sample values as below)
%let rootFolder = C:\DAG\SAS\Tests;
%let fileExt = .sas7bdat;
%findMatches(&rootFolder,&fileExt);

This works fine.

I am trying to run my SAS program through command line with the values for rootFolder and fileExt as command line arguments.

I want to send it as a string with both values separated with a character which will help me parse the 2 values in the program. I chose # as the separator character. So in the bat file I invoke the program as

"C:\Program Files\SAS\SASFoundation\9.2\sas.exe" -SYSPARM C:\DAG\SAS\Tests#.sas7bdat -SYSIN %program_path% -log %log_path% And I have something like below to parse and invoke the above mentioned macro

index = FIND(&SYSPARM,'#');
rootFolderTemp = SUBSTR(&SYSPARM,1,index-1);
fileExtTemp = SUBSTR(&SYSPARM,index+1);

%let rootFolder = rootFolderTemp;
%let fileExt = fileExtTemp;
%findMatches(&rootFolder,&fileExt);


I get the following error messages in the log file

-----------------------------------------------------------------------

123 index = FIND(&SYSPARM,'#');
NOTE: Line generated by the macro variable "SYSPARM".
123 C:\DAG\SAS\Tests#.sas7bdat
_
388
76
ERROR 388-185: Expecting an arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.

124 rootFolderTemp = SUBSTR(&SYSPARM,1,index-1);
NOTE: Line generated by the macro variable "SYSPARM".
124 C:\DAG\SAS\Tests#.sas7bdat
_
388
76
ERROR 388-185: Expecting an arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.

125 fileExtTemp = SUBSTR(&SYSPARM,index+1);
NOTE: Line generated by the macro variable "SYSPARM".
125 C:\DAG\SAS\Tests#.sas7bdat
_
388
76
ERROR 388-185: Expecting an arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.

----------------------------------------------------------------

Any ideas how to resolve this?

Regards,
Neel
Super Contributor
Super Contributor
Posts: 3,174

Re: Specifying/Reading command line arguments for a SAS program

Posted in reply to deleted_user
Your use of &SYSPARM in DATA step code, as you have shared, requires the string be enclosed in double quotations so it is treated as a constant rather than an illegal-named SAS variable.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 10 replies
  • 6352 views
  • 0 likes
  • 3 in conversation