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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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