DATA Step, Macro, Functions and more

Automation help

Reply
Contributor
Posts: 25

Automation help

Hi there, I need to create a macro for finding most recent copy of test data in one table and use it and for another I need to have append of all excel files. I was able to find out the recent file with filevar but something is wrong and I am not able to figure it out. Also the problem is we do not have access to pipe and other system commands.

Following are the file structues that we have

201212_EN1I00001_NL_00001_00.xls

201209_EN1I00001_NL_00001_00.xls

201206_EN1I00001_NL_00001_00.xls

201203_EN1I00001_NL_00001_00.xls

Above 4 files we need to append in table t1 and out of following 2 files I need to get the recent file in table t2. Upto now I finished till finding my recent file. Can anyone help me with the approach?? I am

data null;

  rc=filename('mydir','\\jafile02\IT_Risk\Solvency II\Tracks\Reporting\3Development\2Deliverables\SII Reporting Releases\Testing\R1 Sep 2011 - Test data\SII - Reporting - Test data - Release 1');

  did=dopen('mydir');

  numopts=doptnum(did);

  memcount=dnum(did);

  if (memcount gt 0) then

   do i = 1 to memcount;

      filename=dread(did,i);

      fid = mopen(did, filename,'i',0,'d');

      optname=foptname(fid,2);

       recfm=finfo(fid,optname);

      optname=foptname(fid,3);

       lrecl=finfo(fid,optname);
    b=scan(filename,2,'_');
    if b='EN1I00001' then c= scan(filename,1,'_');
  else c= .;

      rc=fclose(fid);

       put filename = recfm= lrecl= b= c=;

end;

  rc=dclose(did);

run;

Any help is really appreciated......

SAS Employee
Posts: 104

Automation help

It would be helpful to konw the operating system on which you are running SAS.  If Windows, you can extract the creation dat of the file using the FINFO function.  I'd recommend using something like this:

data _null_;
   rc=filename('mydir','\\jafile02\IT_Risk\Solvency II\Tracks\Reporting\3Development\2Deliverables\SII Reporting Releases\Testing\R1 Sep 2011 - Test data\SII - Reporting - Test data - Release 1');
   did=dopen('mydir');
   numopts=doptnum(did);
   memcount=dnum(did);
   if memcount then
      do i = 1 to memcount;
         filename=dread(did,i);
         b=scan(filename,2,'_');
         call missing (c);
         if b='EN1I00001' then            
            do;
               C=scan(filename,1,'_');
               fid = mopen(did, filename,'i',0,'d');
               optname=foptname(fid,2);
               recfm=finfo(fid,optname);
               optname=foptname(fid,3);
               lrecl=finfo(fid,optname);
               CrDate=INPUT(finfo(fid,'Create Time'),datetime.);
               format CrDate datetime.;
            end;
         rc=fclose(fid);
         put filename = recfm= lrecl= b= c= crDate= ;
      end;
   rc=dclose(did);
run;
Ask a Question
Discussion stats
  • 1 reply
  • 126 views
  • 0 likes
  • 2 in conversation