1.

Solve : I need to check the number of parameters given for batch submit..?

Answer»

Hi All,

I am creating one BATCH file, in that i dont know how many parameters going to be given for me execute, i want to call one external program for each parameter, so i need create one loop for doing this so please help me in this. i ll paste my code below..

--------------------------------------------------------------------------------
@echo off

:: SAS EXE PATH
set saspath="C:\Program Files\SAS\SAS 9.1\sas.exe"

:: OPTIONS FOR RUNNING SAS PROGRAMS
set options=-nosplash -icon

:: STUDY PATH
set stpath=F:\Share\Sudhakar\
%saspath% -sysin %stpath %%1 %options%
%saspath% -sysin %stpath %%2 %options%

-------------------------------------------------------------------------------------------

In this program i am submitting the each parameter to the SAS session in batch mode, is there any WAY to check the number of parameters given and putting that in a loop like .. do i= 1 to (num of parameter) end

Please help in this

thanks

Sudhakar1. There is an error in your code

Code: [Select]%saspath% -sysin %stpath %%1 %options%
%saspath% -sysin %stpath %%2 %options%

Should be...

Code: [Select]%saspath% -sysin %stpath% %1 %options%
%saspath% -sysin %stpath% %2 %options%

2. Make a temp file for the parameter LIST

echo %1 > params.txt
echo %2 >> params.txt

(maximum of 9)

then

read them out in a loop

Code: [Select]
for /f %%I in ("params.txt") do (
%saspath% -sysin %stpath% %%I %options%
)


Thanks you very much but I might be getting hundreds of parameter, so i cant able to write that in the .txt file for passing and moreover how the input(filenames are the input) will be is by selecting the number of fies in the windows explorer and selecting the batch file macro in the right clik menuQuote

In this program i am submitting the each parameter to the SAS session in batch mode, is there any way to check the number of parameters given and putting that in a loop like .. do i= 1 to (num of parameter) end

Nine parameters are addressable, however you can exceed that limit by shifting the parameter list down (right to left). Doing so, moves the tenth parameter into the ninth spot and the first parameter is dropped from the list.

Code: [Select]@echo off
set count=0
:start
if .%1==. goto next
set /a count=%count%+1
shift
goto start
:next
echo %count% arg(s) were passed

The code above is a SNIPPET for counting the parameter list. You MAY find it helpful in your code.

Good luck.





Discussion

No Comment Found