I'm trying to solve a logical problem:
two binary inputs with up to 6 digits starting from right to left.
Example inputs are below. Note that the sas table has them right justified.
100
1001
101111
111111
111000
100000
100000
110
110
110111
11100
1
The output I'm looking for is based on an AND operator as follows:
operator(1,111110) = 0
operator(1,111111) = 1
operator(100,111111) = 100
operator(100110,111111) = 100110
operator(11100,111011) = 11000
Thanks for your time and help.
Steve
Hi @capam,
This looks like an opportunity to use the BAND function.
Example:
data have;
input (arg1 arg2) (:binary.);
format arg: binary6.;
cards;
1 111110
1 111111
100 111111
100110 111111
11100 111011
;
data want;
set have;
result=input(put(band(arg1, arg2),binary6.),6.);
run;
Result:
arg1 arg2 result 000001 111110 0 000001 111111 1 000100 111111 100 100110 111111 100110 011100 111011 11000
Note that I've converted the result to decimal numbers in order to get rid of the leading zeros. For further processing as binary values, however, you should use band(arg1, arg2) without input(put(...)).
Your input displays one variable.
Each of your operators use two arguments. where from are those arguments taken?
What is the logic of your operators ?
Your input includes a number 100000 which is not of any operator.
It is not clear what you want.
Hi @capam,
This looks like an opportunity to use the BAND function.
Example:
data have;
input (arg1 arg2) (:binary.);
format arg: binary6.;
cards;
1 111110
1 111111
100 111111
100110 111111
11100 111011
;
data want;
set have;
result=input(put(band(arg1, arg2),binary6.),6.);
run;
Result:
arg1 arg2 result 000001 111110 0 000001 111111 1 000100 111111 100 100110 111111 100110 011100 111011 11000
Note that I've converted the result to decimal numbers in order to get rid of the leading zeros. For further processing as binary values, however, you should use band(arg1, arg2) without input(put(...)).
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 16. 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.