Hi all!
I have some SAS-jobs that runs each evening that creates datasets that is used to update dashboards. These tables are appended to already existing datasets.
Sometimes something in these SAS-jobs goes wrong so the datasets is empty, often because there are some capacity issues in the central systems that makes some queries run empty. And if these empty datasets then are appended, then the dashboards shows nothing.
I would rather have a day old data in the dashboards then no data at all and hope the sas-jobs runs fine the next day. I can't find good examples that helps me with what I'm trying to achieve.
So how can I stop the appending of empty datasets, but also let the code below this appending continue to run?
Something like:
if obs > 0 in new_dataset then do;
proc sql; delete from Server.old_dataset; quit;
proc append base=Server.old_dataset data=new_dataset;
run;
end;
Have your SAS admins update to the current maintenance level 3 days before yesterday. There are so many goodies in there (including the use of %IF %THEN %DO %END in "open code") that not updating (which only takes some work, updates are included in your license) is simply dumb.
Having said that, you need to wrap it into a macro for the time being:
%macro rest_of_code;
%if &nobs. gt 0
%then %do;
/* remaining code */
%end;
%mend;
%rest_of_code
Retrieve the obs number from DICTIONARY.TABLES, and use it in a macro condition:
%let nobs = 0; /* in case dataset does not exist at all */
proc sql noprint;
select nobs into :nobs from dictionary.tables
where libname = "WORK" and mename = "NEW_DATASET"; /* upper case here! */
quit;
%if &nobs. gt 0
%then %do;
/* remaining code */
%end;
Have your SAS admins update to the current maintenance level 3 days before yesterday. There are so many goodies in there (including the use of %IF %THEN %DO %END in "open code") that not updating (which only takes some work, updates are included in your license) is simply dumb.
Having said that, you need to wrap it into a macro for the time being:
%macro rest_of_code;
%if &nobs. gt 0
%then %do;
/* remaining code */
%end;
%mend;
%rest_of_code
Hello @wixol87 ,
This is not responding "1-on-1" on your request, but maybe you can use "exit" functionality in your macro.
I like it and use it from time-to-time.
The %GOTO statement is useful in large macros when you want to provide an exit if an error occurs.
%macro check(parm);
%local status;
%if &parm= %then %do;
%put ERROR: You must supply a parameter to macro CHECK.;
%goto exit;
%end;
more macro statements that test for error conditions
%if &status > 0 %then %do;
%put ERROR: File is empty.;
%goto exit;
%end;
more macro statements that generate text
%put Check completed successfully.;
%exit: %mend check;
Koen
Thanks for this. I'll have it in mind if a come across a problem where this could be useful 🙂
That worked like a charm!
Thanks for helping me. Have a great day!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.