BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
AHSU12
Calcite | Level 5
I have a dataset of 8025 participants. I created a composite variable of five items and now I want to create a table of nmiss for each 5 items . That is, the distribution in the sample of 8,025 participants who across these 5 items have 0 missing items, those with 1 missing item, etc, all the way to those with missing values on all 5 items.  However, I could only create a count of missing for each item as shown in below. Any help would be highly appreciated. TIA.
AHSU12_0-1714401316765.png

 

please see the code below.
 
 
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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;

View solution in original post

8 REPLIES 8
AHSU12
Calcite | Level 5
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;

 

I have a dataset of 8025 participants. I created a composite variable of five items and now I want to create a table of nmiss for each 5 items . That is, the distribution in the sample of 8,025 participants who across these 5 items have 0 missing items, those with 1 missing item, etc, all the way to those with missing values on all 5 items.  However, I could only create a count of missing for each item as shown in below. Any help would be highly appreciated. TIA.
AHSU12_0-1714401698814.png

 

yabwon
Onyx | Level 15

Can you provide soem example data ?

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



maguiremq
SAS Super FREQ

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;

maguiremq_0-1714402477083.png


Please provide example data in the future so we can understand what you need.

AHSU12
Calcite | Level 5
Thanks. This worked for me.
yabwon
Onyx | Level 15

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:

yabwon_0-1714403073620.png

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



yabwon
Onyx | Level 15

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;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



AHSU12
Calcite | Level 5
Thanks. This worked.
FreelanceReinh
Jade | Level 19

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 8 replies
  • 943 views
  • 2 likes
  • 4 in conversation