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
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
Try passing the parameter enclosed in quotes. Removing the quotes in the program may be necessary.
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.
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 !
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
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
- on which operating system are you doing this?
- please copy the commandline exactly as you entered it into a {i} window here.
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
I found the solution ! I have to use %QSCAN instead of %SCAN !
thanks for your help !!!
If the code is only
%put =========> &SYSPARM ;
and the prgm launched with 2015, so then the result is correct
%put =========> &SYSPARM ;
=========> 2015
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.