I am reading this blog post:
I copied the code directly from the blog (changed the dataset name to my data), but it doesn't work. Can anyone tell me why? The error in the log is:
data _null_; if 0 then set claims nobs=n; if n=0 then do; put 'NOTE: No suspicious cases were found. Further processing is terminated.'; call execute('endsas;'); end; stop; run;
Please share the actual log lines that generate that error. It almost sounds like there is an issue with the CLAIMS dataset itself and not with your program.
Note that running ENDSAS will not work well if you are using SAS/Studio, Enterprise Guide or some other tool that runs SAS in the background for you. It will literal end the SAS session and the front-end program that send that code to SAS will not be able to show you the LOG or anything else.
Hello,
I do not see an ERROR in your code. Show us the LOG!
I also check the number of observations in a data set that way.
It is a very performant | quick check as it only checks the header portion of the data set (containing the metadata). No record is read!
data work.claims;
length record $ 250;
if 0;
run;
data _NULL_;
if 0 then set work.claims nobs=count;
call symputx('numobs',put(count,8.));
STOP;
run;
%PUT &=numobs;
See also here for the e-mail part of your question :
How to send email using SAS?
https://communities.sas.com/t5/SAS-Communities-Library/How-to-send-email-using-SAS/ta-p/746523
Cheers,
Koen
Maybe something is missing here. The first data step erases all the observations when there are observations, and the second one produces the same error as the original code (if I don't run the first data step).
You have posted two contradictory logs.
The previous one is showing an error because this is no WORK.CLAIMS dataset to set.
This one is showing a strange error that seems to indicate WORK.CLAIMS exists, but is not a valid dataset. Or perhaps it is a VIEW that generates an error?
In general to fix some of these things the simple idea is to set your macro variable to whatever your FAIL condition is. Then do the test and if it does not change the value that you still ahve something to test.
%let nobs=0;
data _null_;
call symputx('nobs',nobs);
stop;
set claims nobs=nobs;
run;
If if you are running a recent enough version of SAS use some open code %IF %THEN %DO END.
%if %sysfunc(exist(work.claims)) %then %do;
data _null_;
call symputx('nobs',nobs);
stop;
set claims nobs=nobs;
run;
%end;
%else %do;
%let nobs=0;
%end;
Hello @kz_ ,
I erase all observations on purpose (to have zero observations).
The 2nd data-step should work fine.
I can submit it over here.
Very weird!
Koen
Claims is a dataset with all desired variables but no observations. Here are all of the log lines after deleting the endsas statement (log is the same either way):
Mostly I was just curious about why the code above doesn't work. I assume it should be correct since it's from a SAS blog post. Anyway, I got my code to work using proc sql count:
proc sql; select count(*) into :n_claims from claims; quit; %if &n_claims = 0 %then %do; [things to do]; %end;
Your initial code works for me.
A select count(*) will also work but needs to travers through the whole table which for a big table will impact on performance. You can for SAS tables query the dictionary tables instead. This doesn't require processing the data and though performance is independent of table size.
%let n_claims=;
proc sql;
select nlobs into :n_claims
from dictionary.tables
where libname='WORK' and memname='CLAIMS';
quit;
%if &n_claims = 0 %then %do;
[things to do];
%end;
I'm querying in above code NLOBS and not NOBS. NLOBS will return the number of non-deleted observations in a SAS table.
If deleting rows in a table using Proc SQL Delete then rows get only logically deleted and NOBS would return a "wrong" count.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.