BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
capam
Pyrite | Level 9

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

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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(...)).

 

View solution in original post

3 REPLIES 3
Shmuel
Garnet | Level 18

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. 

capam
Pyrite | Level 9
Hi,
The source is a table which contains 2 variables of interest which have the same general construct of binary digits that may be up to 6 digits in length.
They are to be multiplied according to an AND operator as shown in the text.
FreelanceReinh
Jade | Level 19

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(...)).

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1169 views
  • 1 like
  • 3 in conversation