BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
10 REPLIES 10
DanielSantos
Barite | Level 11
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.
deleted_user
Not applicable
Thanks Daniel.

Will check the documentation.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
Thanks Scott.

Will refer to the links.
deleted_user
Not applicable
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
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
DanielSantos
Barite | Level 11
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.
deleted_user
Not applicable
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
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 10 replies
  • 8488 views
  • 0 likes
  • 3 in conversation