From: pyite on
I just started to learn sas, but basically i am trying to figure out
how to look through a series of files based on whether or not the file
exists.

data check;

%let n = 8650;
%let path = ms79:[some.directory]server.log;

do until (ok=0);
if fileexist("&path.;&n.") then do ok=1;
end;
else do ok=0;
end;
file "ms31:[test]ftplog.dat" mod;
put "&&n";
%let n = %eval(&n. +1);
end;
run;

so basically i want the thing to keep looping and increase the value
of n by one... but the value of n never increases, and the thing just
loops forever.
From: Tom Abernathy on
If you are just beginning with SAS then avoid the macro language until
you know how SAS code works. You are just going to get yourself
confused.

From the format of your filenames it looks like you might be working
on VMS and looking for the last version of a file and trying to write
that version number to another file? I am not sure if your logic makes
sense in that case (or in any case).

Perhaps you meant something like this.

data _null_;
basename ='ms79:[some.directory]server.log';
first=0;
last=0;
done=0;
do version=1 to 9999 while (done=0);
 found=fileexist(trim(basename)||compress(put(n,10.)));
if not found and first > 0 then done=1;
if found then do;
last=version;
if first=0 then first=version;
end;
end;
file 'ms31:[test]ftplog.dat' mod;
put last;
run;

- Tom Abernathy


On Jul 12, 7:14 pm, pyite <chalewa4ba...(a)gmail.com> wrote:
> I just started to learn sas, but basically i am trying to figure out
> how to look through a series of files based on whether or not the file
> exists.
>
> data check;
>
> %let n    =      8650;
> %let path =      ms79:[some.directory]server.log;
>
> do until (ok=0);
>  if fileexist("&path.;&n.") then do ok=1;
>   end;
>  else do ok=0;
>   end;
>  file "ms31:[test]ftplog.dat" mod;
>  put "&&n";
>  %let n = %eval(&n. +1);
> end;
> run;
>
> so basically i want the thing to keep looping and increase the value
> of n by one... but the value of n never increases, and the thing just
> loops forever.

From: pyite on
Thanks, I will give that a shot tomorrow.

Yes, I am working in VMS, and yes, I am trying to basically loop
through a bunch of log files that all have the same name, the only
thing that changes is the version number.

the reason that I was trying to use that macro variable was because I
couldn't get the regular data step variable to get work the right way
in that quoted string.

On Jul 12, 9:52 pm, Tom Abernathy <tom.aberna...(a)gmail.com> wrote:
> If you are just beginning with SAS then avoid the macro language until
> you know how SAS code works.  You are just going to get yourself
> confused.
>
> From the format of your filenames it looks like you might be working
> on VMS and looking for the last version of a file and trying to write
> that version number to another file? I am not sure if your logic makes
> sense in that case (or in any case).
>
> Perhaps you meant something like this.
>
> data _null_;
>   basename ='ms79:[some.directory]server.log';
>   first=0;
>   last=0;
>   done=0;
>   do version=1 to 9999 while (done=0);
>      found=fileexist(trim(basename)||compress(put(n,10.)));
>      if not found and first > 0 then done=1;
>      if found then do;
>          last=version;
>          if first=0 then first=version;
>      end;
>   end;
>   file 'ms31:[test]ftplog.dat' mod;
>   put last;
> run;
>
> - Tom Abernathy
>
> On Jul 12, 7:14 pm, pyite <chalewa4ba...(a)gmail.com> wrote:
>
>
>
> > I just started to learn sas, but basically i am trying to figure out
> > how to look through a series of files based on whether or not the file
> > exists.
>
> > data check;
>
> > %let n    =      8650;
> > %let path =      ms79:[some.directory]server.log;
>
> > do until (ok=0);
> >  if fileexist("&path.;&n.") then do ok=1;
> >   end;
> >  else do ok=0;
> >   end;
> >  file "ms31:[test]ftplog.dat" mod;
> >  put "&&n";
> >  %let n = %eval(&n. +1);
> > end;
> > run;
>
> > so basically i want the thing to keep looping and increase the value
> > of n by one... but the value of n never increases, and the thing just
> > loops forever.