BookmarkSubscribeRSS Feed
yash82
Calcite | Level 5

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......

1 REPLY 1
SASJedi
SAS Super FREQ

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;
Check out my Jedi SAS Tricks for SAS Users

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
  • 1 reply
  • 723 views
  • 0 likes
  • 2 in conversation