<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: count not missing for multiple variables simultaneously in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/count-not-missing-for-multiple-variables-simultaneously/m-p/857042#M338602</link>
    <description>&lt;P&gt;You can get the result you want something like this;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                                                                                                              
  array counts(*) count1-count50;                                                                                                        
  retain count1-count50 0;                                                                                                               
  set have end=done;                                                                                                                    
  array vars(*) var1-var50;                                                                                                              
  do i=1 to dim(vars) while(vars(i) not in(.,0));                                                                                       
    counts(i)+1;                                                                                                                        
    end;                                                                                                                                
  if done;                                                                                                                              
  total=_N_;                                                                                                                            
  keep total count1-count50;                                                                                                             
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There will be just one row in the output. The variable TOTAL will contain the total number of observations, the variables COUNT1-COUNT50 will contain the number of observations with no missing values for 1,2... up to all 50 variables. If you want the number of observations with missing values as well, subtract the counts from the total.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Feb 2023 14:00:00 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2023-02-03T14:00:00Z</dc:date>
    <item>
      <title>count not missing for multiple variables simultaneously</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-not-missing-for-multiple-variables-simultaneously/m-p/857006#M338594</link>
      <description>&lt;P&gt;I have a list of 50 variables.&lt;/P&gt;&lt;P&gt;I did a proc freq to do counts of missing/not missing values for each variable individually.&lt;/P&gt;&lt;P&gt;I want to do counts of&amp;nbsp;missing/not missing values for multiple variables simultaneously.&lt;/P&gt;&lt;P&gt;I think I need to use a macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc format; value missfmt .,0 ='Missing' other='Not Missing';&lt;BR /&gt;proc freq data=have; format var1 missfmt.; tables var1 / missing missprint nocum;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then I want to add var2 and do a proc freq but the not missing would be that both var1 and var2 are not missing while missing would be that either var1 or var2 is missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then I want to add var3, and so on until var50.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My idea is to see how the number of observations decreases as one extra variable is added.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions on how to do this?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 10:46:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-not-missing-for-multiple-variables-simultaneously/m-p/857006#M338594</guid>
      <dc:creator>Satori</dc:creator>
      <dc:date>2023-02-03T10:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: count not missing for multiple variables simultaneously</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-not-missing-for-multiple-variables-simultaneously/m-p/857012#M338598</link>
      <description>&lt;P&gt;If you have to use PROC FREQ, then I agree that you will need a macro for this. However, PROC FREQ isn't needed, you can do most of this in a data step with ARRAYs. If you just add the values of var1+var2, the value will be missing if either var1 or var2 will is missing. So this gives you the consecutive ability to count missing across all columns. This code is UNTESTED. You will likely get a lot of notes or warnings in the log about missing values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temporary;
    set have;
    array v var1-var50;
    do i=2 to dim(v);
        do j=1 to i-1;
             v(i)=v(i)+v(j);
         end;
    end;
    drop i j;
run;

proc summary data=temporary;
     var v1-v50;
     output out=missings nmiss=/autoname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to count zero as missing, you would add this as the first line in the &lt;FONT face="courier new,courier"&gt;DO J&lt;/FONT&gt; loop&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if v(j)=0 then call missing(v(j));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 12:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-not-missing-for-multiple-variables-simultaneously/m-p/857012#M338598</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-03T12:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: count not missing for multiple variables simultaneously</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-not-missing-for-multiple-variables-simultaneously/m-p/857042#M338602</link>
      <description>&lt;P&gt;You can get the result you want something like this;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                                                                                                              
  array counts(*) count1-count50;                                                                                                        
  retain count1-count50 0;                                                                                                               
  set have end=done;                                                                                                                    
  array vars(*) var1-var50;                                                                                                              
  do i=1 to dim(vars) while(vars(i) not in(.,0));                                                                                       
    counts(i)+1;                                                                                                                        
    end;                                                                                                                                
  if done;                                                                                                                              
  total=_N_;                                                                                                                            
  keep total count1-count50;                                                                                                             
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There will be just one row in the output. The variable TOTAL will contain the total number of observations, the variables COUNT1-COUNT50 will contain the number of observations with no missing values for 1,2... up to all 50 variables. If you want the number of observations with missing values as well, subtract the counts from the total.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 14:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-not-missing-for-multiple-variables-simultaneously/m-p/857042#M338602</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-02-03T14:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: count not missing for multiple variables simultaneously</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-not-missing-for-multiple-variables-simultaneously/m-p/857067#M338608</link>
      <description>&lt;P&gt;First point is that your test is not whether the values is missing or not.&amp;nbsp; Instead you are testing if the value is TRUE or not.&amp;nbsp; SAS will treat missing or zero as FALSE and any other value as TRUE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you want to count the number of observations that have TRUE values for V1 and then TRUE values for V1 and V2.&amp;nbsp; Looks like a simple candidate for a DO loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's make up some data and try it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input v1-v4 ;
cards;
1 2 3 4
1 0 6 7
. 8 9 10
1 2 0 5
6 7 8 9
;

data want;
  set have end=eof;
  array vars v1-v4;
  array nonmiss[4] ;
  do index=1 to dim(vars) while (vars[index]);
    nonmiss[index]+1;
  end;
  if eof;
  keep nonmiss: ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;OBS    nonmiss1    nonmiss2    nonmiss3    nonmiss4

 1         4           3           2           2
&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Feb 2023 15:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-not-missing-for-multiple-variables-simultaneously/m-p/857067#M338608</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-03T15:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: count not missing for multiple variables simultaneously</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-not-missing-for-multiple-variables-simultaneously/m-p/857075#M338611</link>
      <description>&lt;P&gt;FYI - this post may have some interesting visualization and analysis options for you to explore your patterns of missing data.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2017/11/29/visualize-patterns-missing-values.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2017/11/29/visualize-patterns-missing-values.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/173636"&gt;@Satori&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a list of 50 variables.&lt;/P&gt;
&lt;P&gt;I did a proc freq to do counts of missing/not missing values for each variable individually.&lt;/P&gt;
&lt;P&gt;I want to do counts of&amp;nbsp;missing/not missing values for multiple variables simultaneously.&lt;/P&gt;
&lt;P&gt;I think I need to use a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want is something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format; value missfmt .,0 ='Missing' other='Not Missing';&lt;BR /&gt;proc freq data=have; format var1 missfmt.; tables var1 / missing missprint nocum;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then I want to add var2 and do a proc freq but the not missing would be that both var1 and var2 are not missing while missing would be that either var1 or var2 is missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then I want to add var3, and so on until var50.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My idea is to see how the number of observations decreases as one extra variable is added.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestions on how to do this?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;/LI-SPOILER&gt;</description>
      <pubDate>Fri, 03 Feb 2023 16:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-not-missing-for-multiple-variables-simultaneously/m-p/857075#M338611</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-02-03T16:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: count not missing for multiple variables simultaneously</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-not-missing-for-multiple-variables-simultaneously/m-p/857703#M338901</link>
      <description>&lt;P&gt;How can I do this if I want to mix both numeric and character variables?&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 09:31:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-not-missing-for-multiple-variables-simultaneously/m-p/857703#M338901</guid>
      <dc:creator>Satori</dc:creator>
      <dc:date>2023-02-08T09:31:17Z</dc:date>
    </item>
  </channel>
</rss>

