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

Hi,

 

I wish to sum binary integers and create a new var as the sum of each record. A percentage of each type of occurrence is then computed. An example is shown below.

 

'var1' is an available binary integer of type numeric. 'sum_var1' is to be computed from each binary integer (var1). 'counts of n' is the number of occurrences in sum_var1 of 1, 2, 3, etc. 'total counts' is the value given in Properties-->Advanced-->Rows for the table of interest. 

 

 

 var1sum_var1 
 10001 
 1001 
 1001 
 1000102 
 1000113 
 11 
 1001 
 10001 
 1000012 
 110002 
 11 
 1000012 
 1000001 
 100001 
 1010002 
counts of 19% of 160
counts of 25% of 233.33333
counts of 31% of 36.666667
total counts15  

 

Thanks.

capam

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Thanks for the clarification. So, your integers are in fact decimal integers (which happen to consist of 0s and 1s)?

 

Then you don't need formats or informats for binary numbers:

data Slip_Slide_Incipient_ON_sum;
set Slip_Slide_Incipient_ON_sum;
SS_sum = countc(put(Slip_Slides_DP, 6.),'1');
run;

View solution in original post

5 REPLIES 5
FreelanceReinh
Jade | Level 19

Hi @capam,

 

Try this:

data have;
input var1 binary6.;
cards;
1000
100
100
100010
100011
1
100
1000
100001
11000
1
100001
100000
10000
101000
;

data want;
set have;
sum_var1=countc(put(var1, binary6.),'1');
run;

proc freq data=want;
tables sum_var1;
run;
capam
Pyrite | Level 9

Thanks Free for the quick response.

 

I get the following: 

var1sum_var1
10002
1002
1002
1000103
1000114
11
1002
10002
1000012

 

It should be 

 

var1sum_var1
10001
1001
1001
1000102
1000113
11
1001
10001
1000012

capam

FreelanceReinh
Jade | Level 19

@capam wrote:

Thanks Free for the quick response.

 

I get the following:

(...)



Please show your code together with usable input data. My code gives the desired result based on the HAVE dataset created from data lines.

capam
Pyrite | Level 9

Typical data:

 

1000
100
100
100010
100011
1
100
1000
100001
11000
1
100001
100000
10000
101000
100000
11
1

 

Type is numeric, length is 8. code is below.

 

data Slip_Slide_Incipient_ON_sum;
set Slip_Slide_Incipient_ON_sum;
SS_sum = countc(put(Slip_Slides_DP, binary6.),'1');
run;

FreelanceReinh
Jade | Level 19

Thanks for the clarification. So, your integers are in fact decimal integers (which happen to consist of 0s and 1s)?

 

Then you don't need formats or informats for binary numbers:

data Slip_Slide_Incipient_ON_sum;
set Slip_Slide_Incipient_ON_sum;
SS_sum = countc(put(Slip_Slides_DP, 6.),'1');
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1661 views
  • 0 likes
  • 2 in conversation