BookmarkSubscribeRSS Feed
leeshea06
Calcite | Level 5

Hi, is there a quick way to count number of occurrence of "2", and number of missings (count separately) for x? thanks! Lee
data have;
input id x;
datalines;
id x
1 1
2 2
3 2
4 .
5 1
6 2
7 .
8 1
;

 

4 REPLIES 4
Tom
Super User Tom
Super User

PROC FREQ is an easy way to count.

proc freq data=have ;
  where x in (. 2);
  tables x / missing;
run;
novinosrin
Tourmaline | Level 20
data have;
input id x;
datalines;
1 1
2 2
3 2
4 .
5 1
6 2
7 .
8 1
;

proc freq data=have;
 where x in (.,2);
 tables x/list missing;
run;
PeterClemmensen
Tourmaline | Level 20

Use PROC FREQ and remember the Missing Option.

 

data have;
input id x;
datalines;
id x
1 1
2 2
3 2
4 .
5 1
6 2
7 .
8 1
;

proc freq data = have;
   tables x / missing nocum nopercent;
run;
Ksharp
Super User
Maybe I am full head of SQL.

data have;
input id x;
datalines;
id x
1 1
2 2
3 2
4 .
5 1
6 2
7 .
8 1
;

proc sql;
select sum(x=2) as n_2,nmiss(x) as n_miss
from have;
quit;

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

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
  • 1198 views
  • 4 likes
  • 5 in conversation