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.
Thanks in advance for your help.
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;
It's not clear to me how you get the results. Explain in more detail. Thanks!
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;
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.
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.