Benötigen Sie Hilfe beim Erstellen einer BAT-Datei zum Ausführen von SAS-Jobs?


0

Unter Windows 7 benötige ich eine .bat-Datei, die Dateien in einem Ordner ausführt, wenn ich sie dort ablege. Ich möchte zum Beispiel, dass Dateien mit dem Suffix .sas ausgeführt und nach der Ausführung umbenannt werden. Ich möchte, dass Zehenprogramme nacheinander und nicht gleichzeitig ausgeführt werden. Ich bin auf meiner Schlägerprogrammierung verrostet.

Ich kann Folgendes zum Laufen bringen,

cd C:\Users\ABC\Dropbox\XYZ\Runlibrary
timeout /t 15
"C:\Program Files\SASHome2-94\SASFoundation\9.4\sas.exe"  -sysin  "program5.sas"
ren "program5.sas" "program5.done"

Aber jetzt wollen Sie eine Schleife und die Möglichkeit, alle .SAS-Programme im Ordner ausführen zu lassen. So etwas wie

do (the following 1 million times) 
timeout /t 15
for %f in (*.sas) do "C:\Program Files\SASHome2-94\SASFoundation\9.4\sas.exe"  -sysin  "%f"
for %f in (*.sas) do ren "*.sas" "*.done"

Gedanken, Links oder Beispielcode?

Antworten:


0

Hier ist etwas, das ich erfunden habe, ich habe nichts davon getestet, aber probiere es aus, da es eine Schleife haben soll, bis du es tötest:

@echo off
:: Setting max_count to '0' makes this an infinite loop, you can set it to 10000000 if you want or leave it at 0
set max_count=0

:: Location where the .sas files are stored; '.' means current directory
set sas_dir=.

:: counter should be '0' 
set counter=0

:: Starting the loop
:start_loop
set /a counter+=1

:: Looking for .sas files to execute
if exist "%sas_dir%\*.sas" for /f "tokens=1* delims=" %%f in ('dir /b /o:n /a:-d "%sas_dir%\*.sas"') do (
    echo INFO: Running %%f
    call "C:\Program Files\SASHome2-94\SASFoundation\9.4\sas.exe" -sysin "%%~pnxf"
    rename "%%~pnxf" "%%~pnf.done"
)

:: Stats
echo INFO: Looped Count: %counter%; Reloop Time: 15 secs

:: Waiting 15 secs to reloop
timeout /t 15 >nul

:: Checking Max Counter
if "%max_count%"=="%counter%" (
    echo INFO: Looping completed with "%max_count%" counts, exiting...
    goto end
)

:: relooping
goto start_loop

:end

Hier ist eine Seite, die ich als informativ empfand for Schleifen und andere Stapelfragen: http://judago.webs.com/batchforloops.htm

Durch die Nutzung unserer Website bestätigen Sie, dass Sie unsere Cookie-Richtlinie und Datenschutzrichtlinie gelesen und verstanden haben.
Licensed under cc by-sa 3.0 with attribution required.