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

UNIQUE picks all unique values, and COUNTUNIQUE counts the number of the unique values. For example,

proc iml;
call randseed(1);
x=randfun(5000,"poi",1000);
ux=unique(x);
cux=countunique(x);
quit;

This code simulates X~Poisson(1000) 5000 times. There are 187 unique values from 889 to 1108. Is there any efficient way to get the number of observations for each unique value? For example, 47 out of 5000 observations are X=1000. I use

do i=1 to cux;
if i=1 then n=sum(x=ux[i]);
else n=n||sum(x=ux[i]);
end;

but am looking for a better one.

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Sure, Use CALL TABULATE to get the unique values and the counts in one call:

 

proc iml;
call randseed(1);
x=randfun(5000,"poi",1000);
call tabulate(values, count, x);

View solution in original post

1 REPLY 1
Rick_SAS
SAS Super FREQ

Sure, Use CALL TABULATE to get the unique values and the counts in one call:

 

proc iml;
call randseed(1);
x=randfun(5000,"poi",1000);
call tabulate(values, count, x);

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 1 reply
  • 1013 views
  • 2 likes
  • 2 in conversation