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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 581 views
  • 1 like
  • 4 in conversation