☑ This topic is solved.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 04-29-2024 10:39 AM
(1572 views)
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.
please see the code below.
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
8 REPLIES 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. This worked for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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:
_______________
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. This worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;