BookmarkSubscribeRSS Feed
pavelr
Obsidian | Level 7

There is a need to copy a SAS dataset between remote servers, then periodically check whether this dataset has been modified since the last check. If it has been modified then copy it again. The source and target servers have different encoding, so I need to re-build this dataset to make it correspond to a new encoding, but at the same time I want to preserve its metadata (modate) to be able to determine whether it was modified. So, to copy it I use proc datasets; copy with noclone and datecopy options:

proc datasets;
copy
out=&sourcelib.
noclone
datecopy
in=&targetlib.;
select &source_name.;
run;

 

But when when this dataset is copied, its modification date (modate) is changed by several hours reflecting the timezone of my session (which is different from the timezone of the source server). So, for example, the dataset was modified at 11DEC20:10:23:55, but the modate after copying would show 11DEC20:12:23:55. And now if I compare the modification dates of this dataset located at the source and target servers - they will be different and I cannot determine that it has been modified.

How to avoid this problem with the timezone? Can I force SAS not to change modification date? Or is there another solution to determine that the dataset has been modified?

Would appreciate any help.

1 REPLY 1
andreas_lds
Jade | Level 19

I don't see an easy solution for this problem. Maybe an os-command can change/manipulate the modification date after the dataset was copied. You could store the original modification date in an extend attribute.

Just an idea:

/* something to play with, work.cars acts as source */
data work.cars;
   set sashelp.cars;
run;

/* Store the modification date in the macro variable "modDate" */
data _null_;
   set sashelp.vtable(where=(Libname = 'WORK' and Memname = 'CARS'));
   call symputx('modDate', modate);
run;

/* Copy, sasuser acts as target-lib */
proc datasets nolist;
   copy out=sasuser in=work noclone datecopy;
      select cars;
quit;

/* Add the extend attribute */
proc datasets library= sasuser nolist;
   modify cars;
      xattr add ds original_mod_date = &modDate.;
quit;

/* Later compare the current modification date with the xattr
 * Execute only the first data-step creating work.cars to simulate an
 * update of your source dataset */
data _null_;
   set sashelp.vxattr( 
      where= (Libname = 'SASUSER' and Memname = 'CARS' 
      and lowcase(xattr) = 'original_mod_date')
   );
   set sashelp.vtable(
      keep= Libname Memname Modate
      where= (Libname = 'WORK' and Memname = 'CARS')
   );

   CloneModDate = input(xvalue, best.);

   put CloneModDate= datetime.;
   put modate=;

   if intck('DTSECONDS', modate, CloneModDate) then do;
      put "Dataset was updated";
   end;
   else do;
      put "Still unchanged";
   end;

   call symputx('has_changed', intck('DTSECONDS', modate, CloneModDate) ^= 0);
run;

%put &=has_changed;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1065 views
  • 0 likes
  • 2 in conversation