BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nasser_DRMCP
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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

View solution in original post

9 REPLIES 9
andreas_lds
Jade | Level 19

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

Kurt_Bremser
Super User

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.

Nasser_DRMCP
Lapis Lazuli | Level 10

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 !

Kurt_Bremser
Super User

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
Nasser_DRMCP
Lapis Lazuli | Level 10

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

Nasser_DRMCP
Lapis Lazuli | Level 10

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

Nasser_DRMCP
Lapis Lazuli | Level 10

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

thanks for your help !!!

 

Nasser_DRMCP
Lapis Lazuli | Level 10

If the code is only

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

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

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

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!

How to Concatenate Values

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.

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