DATA Step, Macro, Functions and more

launch batch with multiple parameter retrieve scan

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 75
Accepted Solution

launch batch with multiple parameter retrieve scan

Hello,

 

I would like to lauch a sas prgm in batch with multiple parameters by using sysparm.

this code below works well in sas guide

%let SYSPARM = 2015 2017 ;

%let p_GENERATION_START = %scan(&sysparm,1) ;

%let p_GENERATION_END = %scan(&sysparm,2) ;

%put  &p_GENERATION_START &p_GENERATION_END ; this line returns 2015 2017 as intended.

 

But whenever I launch the prgm in batch by fill in 2015 2017, I notice that only the first parameter (2015) is put within the log file.Many thanks in advance for your help.

 

Nasser


Accepted Solutions
Solution
‎07-19-2017 11:05 AM
Super User
Posts: 7,758

Re: launch batch with multiple parameter retrieve scan

Posted in reply to Nasser_alfea

Your data step variables are gone as soon as the data _null_ finishes, so the log of your program (saved as test.sas in my environment and called with the commandline as stated in my previous post) looks like this:

1          %put =========> &SYSPARM ;
=========> 2015 2017
2
3          data _null_ ;
4          p_GENERATION_START = scan("&sysparm",1) ;
5          p_GENERATION_END = scan("&sysparm",2) ;
6          run ;

NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


7
8          %put===============> p_GENERATION_START p_GENERATION_END ;
===============> p_GENERATION_START p_GENERATION_END

You can see that sysparm contains the whole "2015 2017" string without the quotes, but the %put fails. Adapt your code like this to get macro variables:

%put =========> &SYSPARM;

%let p_GENERATION_START = %scan(&sysparm,1);
%let p_GENERATION_END = %scan(&sysparm,2);

%put===============> &p_GENERATION_START &p_GENERATION_END;

after running

sas test.sas -sysparm "2015 2017"

you'll get

1          %put =========> &SYSPARM;
=========> 2015 2017
2
3          %let p_GENERATION_START = %scan(&sysparm,1);
4          %let p_GENERATION_END = %scan(&sysparm,2);
5
6          %put===============> &p_GENERATION_START &p_GENERATION_END;
===============> 2015 2017
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super Contributor
Posts: 345

Re: launch batch with multiple parameter retrieve scan

Posted in reply to Nasser_alfea

Try passing the parameter enclosed in quotes. Removing the quotes in the program may be necessary.

Super User
Posts: 7,758

Re: launch batch with multiple parameter retrieve scan

Posted in reply to Nasser_alfea

Just tested @andreas_lds suggestion on AIX with SAS 9.4.

sas test.sas -sysparm "2015 2017"

resulted in this log:

1          data _null_;
2          do i = 1 to countw("&sysparm");
3            x1 = scan("&sysparm",i);
4            put x1=;
5          end;
6          run;

x1=2015
x1=2017

At least on a UNIX, the commandline parser removes the quotes when dissecting the whole commandline.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Frequent Contributor
Posts: 75

Re: launch batch with multiple parameter retrieve scan

Posted in reply to KurtBremser

Hello,

thanks for your response but It does not work. my prgm bellow :

 

%put =========> &SYSPARM ;

 

data _null_ ;

p_GENERATION_START = scan("&sysparm",1) ;

p_GENERATION_END = scan("&sysparm",2) ;

run ;

 

%put===============> p_GENERATION_START p_GENERATION_END ;

 

and then I launch it with the param 2017 2015 (so without quotes) but put returns nothing !

Solution
‎07-19-2017 11:05 AM
Super User
Posts: 7,758

Re: launch batch with multiple parameter retrieve scan

Posted in reply to Nasser_alfea

Your data step variables are gone as soon as the data _null_ finishes, so the log of your program (saved as test.sas in my environment and called with the commandline as stated in my previous post) looks like this:

1          %put =========> &SYSPARM ;
=========> 2015 2017
2
3          data _null_ ;
4          p_GENERATION_START = scan("&sysparm",1) ;
5          p_GENERATION_END = scan("&sysparm",2) ;
6          run ;

NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


7
8          %put===============> p_GENERATION_START p_GENERATION_END ;
===============> p_GENERATION_START p_GENERATION_END

You can see that sysparm contains the whole "2015 2017" string without the quotes, but the %put fails. Adapt your code like this to get macro variables:

%put =========> &SYSPARM;

%let p_GENERATION_START = %scan(&sysparm,1);
%let p_GENERATION_END = %scan(&sysparm,2);

%put===============> &p_GENERATION_START &p_GENERATION_END;

after running

sas test.sas -sysparm "2015 2017"

you'll get

1          %put =========> &SYSPARM;
=========> 2015 2017
2
3          %let p_GENERATION_START = %scan(&sysparm,1);
4          %let p_GENERATION_END = %scan(&sysparm,2);
5
6          %put===============> &p_GENERATION_START &p_GENERATION_END;
===============> 2015 2017
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Frequent Contributor
Posts: 75

Re: launch batch with multiple parameter retrieve scan

Posted in reply to KurtBremser

thanks Kurt but I do not manage. I copy/past what you suggests then my only code is...

%put =========> &SYSPARM;

%let p_GENERATION_START = %scan(&sysparm,1);

%let p_GENERATION_END = %scan(&sysparm,2);

%put===============> &p_GENERATION_START &p_GENERATION_END;

 

and I launch with "2015 2017"

But the log is named 2017 (why not my progm name ???) and the log is empty

Super User
Posts: 7,758

Re: launch batch with multiple parameter retrieve scan

Posted in reply to Nasser_alfea

- on which operating system are you doing this?

- please copy the commandline exactly as you entered it into a {i} window here.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Frequent Contributor
Posts: 75

Re: launch batch with multiple parameter retrieve scan

Posted in reply to KurtBremser

I lauch the program via within unix system (Putt). I don't know exactly the command because a menu has been created. I use the menu. I just have to specify the prgm name and the step after the prompt is "SYSPARM ?"  I have to specify 2015 2016

Frequent Contributor
Posts: 75

Re: launch batch with multiple parameter retrieve scan

Posted in reply to KurtBremser

I found the solution ! I have to use %QSCAN instead of %SCAN !

thanks for your help !!!

 

Frequent Contributor
Posts: 75

Re: launch batch with multiple parameter retrieve scan

Posted in reply to Nasser_alfea

If the code is only

%put =========> &SYSPARM ;

and the prgm launched with 2015, so then the result is correct

      %put =========> &SYSPARM ;
=========> 2015

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 246 views
  • 0 likes
  • 3 in conversation