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
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;
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;
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;
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
And another approach:
proc sql; create table want as select num , count(num) as Numcount from have group by num; quit;
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!
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.
Ready to level-up your skills? Choose your own adventure.