Hi:
You should read about the difference between GLOBAL and LOCAL macro variables. If you create &ERROR in a macro program, generally &ERROR would be "local" in scope and therefore, would NOT be available AFTER %Error_chk had finished processing.
Also, you do NOT show what's inside %history_rpt or %err_prt, however, unless they are data step programs, you do not need to invoke them INSIDE a DATA _NULL_ step (which seems to be happening in your %Report_selection macro program). A %IF test can be done inside a macro program without being in a datasetp program. In fact , if %history_rpt or %err_prt use ODS or SAS procedures, you're probably better off just getting rid of the DATA _NULL_ that you have in the second macro definition.
Finally, I see where you set &ERROR to 1, but I don't see where you set or initialize it to 0. Macro variables are initially set to nothing or NULL, not zero. You might put --
[pre]
%global error;
%let error = 0;
[/pre]
before the proc sql step.
That may not solve all your issues, however. You probably have a logic problem, as well. The first rule of writing a macro program is beginning with a working SAS program. Your underlying assumption seems to be that you have an error if SQLOBS is 0. However, when I run the same query -- once to create a table and a second time to create a view, I get sqlobs=0 for the view. According to the documentation, SQLOBS always is 0 if a view is created (refer to to the documentation here:
http://support.sas.com/documentation/cdl/en/sqlproc/59727/HTML/default/a001360983.htm#a001404680) And, you can prove it to yourself, by running these 2 SQL steps:
[pre]
1264 proc sql;
1265 create table work.reg1 as
1266 select * from sashelp.shoes
1267 where region = 'Asia';
NOTE: Table WORK.REG1 created, with 14 rows and 7 columns.
1268 %put **** 1) create table sqlobs = &sqlobs;
**** 1) create table sqlobs = 14
1269 quit;
NOTE: PROCEDURE SQL used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
1270
1271 proc sql;
1272 create view WORK.reg2
1273 as SELECT * FROM sashelp.shoes
1274 where region = 'Asia';
NOTE: SQL view WORK.REG2 has been defined.
1275 %put **** 2) create view sqlobs = &sqlobs;
**** 2) create view sqlobs = 0
1276 Quit;
NOTE: PROCEDURE SQL used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
[/pre]
This means that even if &ERROR were available, it would always be set to 1, because as long as you are basing SQLOBS on view creation, it will always be 0.
A different technique for testing whether there are any records in a dataset is to capture NOBS from dictionary.tables:
[pre]
proc sql;
select (nobs - delobs) into :numobs
from dictionary.tables
where libname = "WORK" and memname = "REVISION_GT_1";
quit;
%let numobs = &numobs;
%put *** number of obs in dataset is: &numobs;
[/pre]
Then you could test &NUMOBS:
%if &NUMOBS = 0 %then %do; %let error = 1; %end;
OR, you could just use &NUMOBS instead of &ERROR in your macro program.
cynthia