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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 1103 views
  • 0 likes
  • 4 in conversation