Hi
I am trying to do bit testing. It works when I write it as a data step but fails if i wrap it inside a macro. What am i missing here ? Below is the simple code. The one in bold works but the one in red doesn't.
options symbolgen mlogic mprint;
%macro test;
%let a = 4096;
%let b= '1............'b;
data a;
%if &a =&b %then %do;
x=10;
%end;
run;
%mend;
%test;
proc print data=a;
run;
%let a = 4096;
%let b= '1............'b;
data a;
if &a =&b then do;
x=10;
end;
run;
proc print data=a;
run;
Macro IF statements (%IF) can't do bit-type comparisons, only text ones. Why do you want to do it in a macro statement?
I am using it to compare sysinfo value set by Proc Compare. The macro takes two datasets, does Proc Compare and then a loop executes 16 times to compare sysinfo value with the bit value and if matched, save the error description. There are over 3000 datasets to be compared so i was using a macro.
Then you can use macro to generate DATA step IF statements. Regarding PROC COMPARE I've found this logic helpful. I don't think you have to test for every possible bit code.
%let base = MyBaseData;
%let compare = MyCompareData;
proc compare base = &base
comp = &compare
listvar out = difs outnoequal
;
ID MyIDVar;
run;
%let rc = &sysinfo;
data _null_;
%* Test for data set label ;
if &rc = '1'b then
put "<<<< &compare.: Data sets have different labels";
%* Test for data set types ;
if &rc = '1.'b then
put "<<<< &compare.: Data set types differ";
%* Test for label ;
if &rc = '1.....'b then
put "<<<< &compare.: Variable has different label";
%* Test for base observation ;
if &rc = '1......'b then
put "<<<< &compare.: Base data set has observation not in comparison data set";
%* Test for length ;
if &rc = '1....'b then
put "<<<< &compare.: Variable has different lengths between the base data set and the comparison data set";
%* Variable in base data set not in compare data set;
if &rc ='1..........'b then
put "<<<< &compare.: Variable in base data set not found in comparison data set";
%* Comparison data set has variable not in base data set ;
if &rc = '1...........'b then
put "<<<< &compare.: Comparison data set has variable not contained in the base data set";
%* Test for values ;
if &rc = '1............'b then
put "<<<< &compare.: A value comparison was unequal";
%* Conflicting variable types;
if &rc ='1.............'b then
put "<<<< &compare.: Conflicting variable types between the two data sets being compared";
run;
Hello,
You can use the band function as follows :
%let VALUE_COMPARISON_UNEQUAL=4096;
%macro compare(ds1,ds2);
proc compare base=&ds1. comp=&ds2. noprint;
run;
%if %sysfunc(band(&sysinfo., &VALUE_COMPARISON_UNEQUAL.)) %then %put Different values found;
%mend;
data a;
x=1;
run;
data b;
x=1;
y=2;
run;
data c;
x=2;
run;
%compare(a,b);
%compare(a,c);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.