Pyrite | Level 9

## divide data into components and count new columns

I use Innov 9.4.

From a given table some of the data appears as below:

 1 10 11 1 100 1000 10100 1000 1000

How do I design an algorithm that outputs the following:

 slot 5 slot4 slot3 slot2 slot1 3 2 2 3 1

The above is a simple count of each of the binary slots.

1 ACCEPTED SOLUTION

Accepted Solutions
Pyrite | Level 9

## Re: divide data into components and count new columns

Thanks. The above works if some simple logic is added.

As an example:

`ones = mod(x,10);`

if ones<1 then ones= 0;
else ones= 1;

4 REPLIES 4
Diamond | Level 26

## Re: divide data into components and count new columns

It's not clear to me how you get the results. Explain in more detail. Thanks!

--
Paige Miller

## Re: divide data into components and count new columns

Hi @capam,

Try this:

``````data have;
input x;
cards;
1
10
11
1
100
1000
10100
1000
1000
;

%let n=5;

data want(keep=s:);
retain slot&n-slot1;
array slot[&n];
do until(last);
set have end=last;
c=put(x,&n..);
do i=1 to &n;
slot[i]+(char(c,i)='1');
end;
end;
run;

proc print data=want noobs;
run;``````
Super User

## Re: divide data into components and count new columns

This pulls those values apart:

```data junk;
input x;
ones = mod(x,10);
tens = mod(int(x/10),10);
hunds = mod(int(x/100),10);
thous = mod(int(x/1000),10);
tenthous = mod(int(x/10000),10);
datalines;
1
10
11
1
100
1000
10100
1000
1000
;
run;```

Since your example shows totals you would use any of the summary or report procedures such as Means or summary, report or tabulate to get sums.

Slot? Really? And the order you named them makes little sense at all in relation to the positions. Though displaying the numeric value with a Z5. format might help.

Pyrite | Level 9

## Re: divide data into components and count new columns

Thanks. The above works if some simple logic is added.

As an example:

`ones = mod(x,10);`

if ones<1 then ones= 0;
else ones= 1;

Discussion stats
• 4 replies
• 709 views
• 0 likes
• 4 in conversation