BookmarkSubscribeRSS Feed
avinashjha1787
Calcite | Level 5

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;

4 REPLIES 4
SASKiwi
PROC Star

Macro IF statements (%IF) can't do bit-type comparisons, only text ones. Why do you want to do it in a macro statement?

avinashjha1787
Calcite | Level 5

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.

SASKiwi
PROC Star

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;
 
gamotte
Rhodochrosite | Level 12

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);

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 657 views
  • 2 likes
  • 3 in conversation