BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ariogon
Calcite | Level 5

Hi,

 

I have a table with just one column with hundreds of numbers:

1

2

7

2

8

6

7

...

and I want a table with the information of number of registers greater than 1, greater than 2, greater than 3 ann so on, until 48, without having to repeat 48 times select count(*) from table where column>n, where n is 1, 2, 3....

 

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep, and show what the output should look like.  At a guess:

data have;
  input num;
datalines;
1
2
7
2
8
6
7
;
run;

data want;
  set have;
  array res{48} 8;
  retain res:;
  do i=1 to 48;
    if num >= i then res{i}=sum(res{i},1);
  end;
run;

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep, and show what the output should look like.  At a guess:

data have;
  input num;
datalines;
1
2
7
2
8
6
7
;
run;

data want;
  set have;
  array res{48} 8;
  retain res:;
  do i=1 to 48;
    if num >= i then res{i}=sum(res{i},1);
  end;
run;
PeterClemmensen
Tourmaline | Level 20
data have;
  input num;
datalines;
1
2
7
2
8
6
7
;
run;

proc sort data=have out=temp;
   by num;
run;

data want;
   set temp;
   by num;
   sum+1;
   if last.num & num le 48;
   retain sum;
run;
ariogon
Calcite | Level 5

The output for the data of the example should be a table of 2 columns:

1 6

2 4

3 4

4 4

5 4

6 3

7 1

8 0

9 0

....

48 0

 

ballardw
Super User

And another approach:

proc sql;
   create table want as
   select num , count(num) as Numcount
   from have
   group by num;
quit;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 4 replies
  • 1024 views
  • 1 like
  • 4 in conversation