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 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 5slot4slot3slot2slot1
32231

 

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

Thanks in advance for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
capam
Pyrite | Level 9

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;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
FreelanceReinh
Jade | Level 19

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;
ballardw
Super User

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.

capam
Pyrite | Level 9

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

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