please see the code below.
I think you want to apply the NMISS function to the five values foodinsc1, ..., foodinsc5 in each observation:
/* Create sample data for demonstration */
data have;
array foodinsc[5] (. 7 . 0 .);
foodinsc_scr=.;
run;
/* Count missing values of foodinsc1, ..., foodinsc5 in each observation */
data want;
set have;
nm=nmiss(of foodinsc1-foodinsc5);
run;
/* Obtain frequency distribution */
proc freq data=want;
tables nm;
run;
data merged; set food; foodinsc_scr=sum(foodinsc1_rc, foodinsc2_rc, foodinsc3_rc, foodinsc4_rc, foodinsc5_rc); run; proc means data=merged N NMISS; var foodinsc_scr foodinsc1 foodinsc2 foodinsc3 foodinsc4 foodinsc5; run;
Can you provide soem example data ?
Not sure if this is what you want.
data have;
input id v1 v2 v3;
datalines;
1 . . 3
2 1 2 3
3 . . .
4 1 . .
;
run;
data want (drop = i);
set have;
array _v [*] v:;
total_miss = 0;
do i = 1 to dim(_v);
if missing(_v[i]) then total_miss + 1;
end;
run;
Please provide example data in the future so we can understand what you need.
This example:
data FOOD;
input foodinsc1_rc foodinsc2_rc foodinsc3_rc foodinsc4_rc foodinsc5_rc;
cards;
1 2 3 4 5
1 2 3 4 .
1 2 3 . .
1 2 . . .
. . . . .
1 2 3 4 5
;
run;
data merged;
set food;
foodinsc_scr=sum(foodinsc1_rc, foodinsc2_rc, foodinsc3_rc, foodinsc4_rc, foodinsc5_rc);
run;
proc means data=merged n nmiss;
run;
gives:
To get a dataset try:
data countofmissing;
set merged end=end;
array F(i) food:;
array N[6] _temporary_ (6*0);
array M[6] _temporary_ (6*0);
do over F;
if nmiss(F) then M[i]+1;
else N[i]+1;
end;
if end;
do over F;
variable=vname(F);
missing=M[i];
nonMissing = N[i];
output;
end;
keep V: N: M:;
run;
proc print;
run;
I think you want to apply the NMISS function to the five values foodinsc1, ..., foodinsc5 in each observation:
/* Create sample data for demonstration */
data have;
array foodinsc[5] (. 7 . 0 .);
foodinsc_scr=.;
run;
/* Count missing values of foodinsc1, ..., foodinsc5 in each observation */
data want;
set have;
nm=nmiss(of foodinsc1-foodinsc5);
run;
/* Obtain frequency distribution */
proc freq data=want;
tables nm;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.