Is there a way to check (programmatically) whether a dataset was really copied using proc datasets; copy?
For example, in a program I use proc datasets; copy to copy a dataset, then I need to do some actions with this dataset. But before I do something with this dataset I want to check whether it was really copied (copying was not terminated by a poor connection or but some other reasons). How can I do it in my program?
Thanks for any help!
Ok. How about this. Run Proc Datasets and check the SysCC macro variable for success.
proc datasets nolist;
copy in = sashelp out = work memtype = data;
select class;
run;quit;
%put &=syscc.;
proc datasets nolist;
copy in = abc out = work memtype = data;
select class;
run;quit;
%put &=syscc.;
I don't think Proc Datasets offers that.. Would it be enough to check if the copied dataset exist?
Thanks for your reply. To check if the copied dataset exist is not really enough, because it already exists there, but I need to copy (refresh/replace) this dataset periodically and to know whether proc datasets; copy failed or not. To delete this dataset before copying a new version of it is not an option either.
Ok. How about this. Run Proc Datasets and check the SysCC macro variable for success.
proc datasets nolist;
copy in = sashelp out = work memtype = data;
select class;
run;quit;
%put &=syscc.;
proc datasets nolist;
copy in = abc out = work memtype = data;
select class;
run;quit;
%put &=syscc.;
This should work. I will try it.
Thank you very much!
Well, it doesn't fully solve the problem, because if some other step before proc datasets fails then syscc is set to an error number, so when proc datasets executes afterwards and doesn't fail - the syscc is not reset to 0.
If you get &syscc > 0 then copy failed. (&syscc=4 is a warning - should bechecked).
You can either abort this session and rerun the copy later in a new session or
you can reset it by: %let syscc=0; and continue with other steps.
In last case you need a warning message to show which file was not copied.
You could try FINFO() function to get modification date, see the doc for the details:
Here is example from doc. which may help:
data info;
length infoname infoval $60;
drop rc fid infonum i close;
rc=filename('abc', 'physical-filename');
fid=fopen('abc');
infonum=foptnum(fid);
do i=1 to infonum;
infoname=foptname(fid, i);
infoval=finfo(fid, infoname);
output;
end;
close=fclose(fid);
run;
all the best
Bart
Thank you, Bart! This seems to be a good solution too. Need to look into it.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.