How to pass an %LET argument into a sas script from R?

passing parameters to sas programs in unix
sas shell script parameter
sas include pass parameter
sas sysget

I have an R script that let me run a macro in SAS, like this (inspiration from here):

sas_script <- ""
sas_log <- tempfile()
sas_out <- tempfile()

cmd <- sprintf(
  'sas.exe -nosplash -icon -sysin "%s"  -log "%s" -print "%s"',
  sas_script, sas_log, sas_out

return_code  <- system(cmd)  # Runs sas and saves the return code

But I would like to pass an argument into the macro, so I can run it, for example with all the years from 2010 to 2018. My SAS macro (that calls several other macros) look something like this:

options nocenter nodate nonumber mprint;

%let sti=C:\Mypath\;
%include "&" ;

%let aar=2018;


So instead of %let aar=2018; in sas, I would like to do something like this for(aar in 2010:2018){ code } in R.

Any suggestions?

You can use the -SET option on the SAS command line to pass arguments into SAS. Then use the %SYSGET macro to retrieve those values in your program. For further discussion and an example, see the article "How to pass parameters to a SAS program."

How to pass parameters to a SAS program - The DO Loop, At the top of the program, you can replace the simple %LET you to run SAS programs in batch mode and pass in program parameters. Re: Unix: passing parameter to a SAS program in command line Posted 06-19-2017 (8316 views) | In reply to MariaD The -sysparm in you question should work, you can pass multiple parameters in -sysparm option and parse it using scan function in sas file.

You can use the -sysparm command line option to pass a value into your SAS program. You can reference the value in your SAS program using &sysparm macro variable reference.

Solved: SYSPARM - Pass Command Line Arguments to SAS, Say I have the following SAS program ( Enterprise Guide 1 · SAS Programming for R Users · SAS Viya Enablement · All Courses the Command Prompt syntax to pass these arguments into the SAS program? %let mu=%scan(&sysparm,1); %let variance=%scan(&sysparm,2); %let  This article show how to run a SAS program in batch mode and send parameters into the program by specifying the parameters when you run SAS from a command line interface. This technique has many uses, one of which is to split a long-running SAS computation into a series of less time-intensive computations.

I'm not sure I understand your issue, but if I'm correct you want to loop from a year N to another year M, right ?

So in SAS you can write a loop inside a macro and run the macro. In your example, I'll do :

options nocenter nodate nonumber mprint;

%let sti=C:\Mypath\;
%include "&" ;

%do year = &startyear. %to &endyear.;
    %macro1(aar = &year);

%macro_loop(startyear = 2010, endyear = 2018);

Solved: Unix: passing parameter to a SAS program in comman , I'm trying to pass a parameters for a SAS code that is executed on and then have a few %LET statements which create macro variables which  This post describes how to pass external arguments to R when calling a Rscript with a command line. The case study presented here is very simple: a Rscript is called which needs, as an input, a file name (a text file containing data which are loaded into R to be processed) and which can also […]

Write a reusable SAS/IML module that passes values to R, To keep things simple, let's focus on a specific statistical example. I could define a SAS macro named %MEDIAN that takes name of the The key to the technique is to pass parameters to R by using the SUBMIT statement. Hi. I am new to SAS Batch processing capabilities and SYSPARM functionality. Say I have the following SAS program ( Basically a short program with 3 parameters (mu, variance and seed) that creates 12 random normal variates from a given normal distribution (specified by mu and va

Solved: How to properly quote parameters when passing them , I'm on a Linux SYSTEM calling a SAS program from a cronfile. That SAS program is passing arguments to a SAS. %let param1=2500;. I want to create a sas macro and the parameters are also macro variables, so how can I pass these macro variables into macro? yes, I want to know how to pass them into the Macro. Thanks for your replying. Pass the names not the value. Then you don't have to worry about quoting in the macro call. Also you can't name a macro %INPUT.

[PDF] SAS Programming for R Users, SAS options are additional arguments and they are specific to SAS statements. In R, we generally pass a data frame matrix or vector to analyze it. In SAS Let's create a new program by selecting New Options at the top of the page and then  I am trying to pass a date macro variable into another macro variable and unable to do that. Here is the code that I am using . LET TODAY = %sysfunc(TODAY(),DATE9.);

  • Could you give an example on how that could work, please?
  • When you run a SAS program from the command line you usually use command like sas Instead add in the -sysparm option and your command becomes sas -sysparm 2018 You can then use the value in your SAS program by referencing it as &sysparm.
  • Can't get it to work. I tried cmd <- sprintf( 'sas.exe -nosplash -icon -sysin "%s" -log "%s" -print "%s" -set aar "%s -set aar1 "%s"', sas_script, sas_log, sas_out, aar, aar1 ) and cmd <- sprintf( paste0('sas.exe -nosplash -icon -sysin "%s" -log "%s" -print "%s" -set aar \"', aar,'" -set aar \"', aar1, '"'), sas_script, sas_log, sas_out )
  • What values are you trying to set to the variable aar? Why are you trying to set a value to the same variable multiple times?
  • Well... the sas code is not mine, but guess i could just make aar1 from aar. Is it a problem to add two variables?
  • I guess that is one way to do it. Not quite what i asked for, as I would like to control the startyear and endyear from R, as several other people are working on the SAS code, so would be more convienient for me to just edit the years in R