<?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: Checking for missing data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Checking-for-missing-data/m-p/414203#M279999</link>
    <description>&lt;P&gt;Are the variables all the same type, if so what type?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're using EG, I suggest the Characterize data task, its quite useful.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a worked example for generating the number of missing/non missing but I'm not sure thats what you're looking for....&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/2de1faf1644dc8160fe721056202f111" target="_blank"&gt;https://gist.github.com/statgeek/2de1faf1644dc8160fe721056202f111&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Nov 2017 01:05:30 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-11-17T01:05:30Z</dc:date>
    <item>
      <title>Checking for missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-for-missing-data/m-p/414170#M279997</link>
      <description>&lt;P&gt;Hi everyone!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with&amp;nbsp;400-500&amp;nbsp;variables and I would like to check for&amp;nbsp;missing data and generate a line list for observations with missing data.&lt;/P&gt;&lt;P&gt;so far I have:&lt;/P&gt;&lt;P&gt;data _NULL_;&lt;/P&gt;&lt;P&gt;set dataset1;&lt;/P&gt;&lt;P&gt;if numvar=.&lt;/P&gt;&lt;P&gt;then put id=;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, in addition to the ID, I would also like SAS to print the variables with the missing value for an observation, since I would like to know what variables are actually missing. Is it possible to do that?&lt;/P&gt;&lt;P&gt;Thank you for any advice in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2017 22:38:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-for-missing-data/m-p/414170#M279997</guid>
      <dc:creator>michan22</dc:creator>
      <dc:date>2017-11-16T22:38:31Z</dc:date>
    </item>
    <item>
      <title>Re: Checking for missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-for-missing-data/m-p/414187#M279998</link>
      <description>&lt;P&gt;With data like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input one two three;
datalines;
9	2	6
4	.	3
4	9	3
.	10	.
0	3	1
6	.	9
4	7	9
3	8	1
9	1	5
0	1	0
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data two;
	set one;
	array myvariables one -- three; 
	length names $50;
	names = '';
	do over myvariables; 
		if cmiss(myvariables) then names = catx(', ', names, vname(myvariables));
	end;
run;
 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And get this:&lt;/P&gt;
&lt;TABLE width="289"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="41"&gt;one&lt;/TD&gt;
&lt;TD width="72"&gt;two&lt;/TD&gt;
&lt;TD width="64"&gt;three&lt;/TD&gt;
&lt;TD width="112"&gt;names&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="41"&gt;9&lt;/TD&gt;
&lt;TD width="72"&gt;2&lt;/TD&gt;
&lt;TD width="64"&gt;6&lt;/TD&gt;
&lt;TD width="112"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="41"&gt;4&lt;/TD&gt;
&lt;TD width="72"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64"&gt;3&lt;/TD&gt;
&lt;TD width="112"&gt;two&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="41"&gt;4&lt;/TD&gt;
&lt;TD width="72"&gt;9&lt;/TD&gt;
&lt;TD width="64"&gt;3&lt;/TD&gt;
&lt;TD width="112"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="41"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="72"&gt;10&lt;/TD&gt;
&lt;TD width="64"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="112"&gt;one, three&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="41"&gt;0&lt;/TD&gt;
&lt;TD width="72"&gt;3&lt;/TD&gt;
&lt;TD width="64"&gt;1&lt;/TD&gt;
&lt;TD width="112"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="41"&gt;6&lt;/TD&gt;
&lt;TD width="72"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64"&gt;9&lt;/TD&gt;
&lt;TD width="112"&gt;two&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="41"&gt;4&lt;/TD&gt;
&lt;TD width="72"&gt;7&lt;/TD&gt;
&lt;TD width="64"&gt;9&lt;/TD&gt;
&lt;TD width="112"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="41"&gt;3&lt;/TD&gt;
&lt;TD width="72"&gt;8&lt;/TD&gt;
&lt;TD width="64"&gt;1&lt;/TD&gt;
&lt;TD width="112"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="41"&gt;9&lt;/TD&gt;
&lt;TD width="72"&gt;1&lt;/TD&gt;
&lt;TD width="64"&gt;5&lt;/TD&gt;
&lt;TD width="112"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="41"&gt;0&lt;/TD&gt;
&lt;TD width="72"&gt;1&lt;/TD&gt;
&lt;TD width="64"&gt;0&lt;/TD&gt;
&lt;TD width="112"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe that gives you a place to start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming an ID column I didn't use, then adding&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	if not cmiss(names);
	drop one -- three;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;on the end of that may be exactly what you want.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2017 23:34:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-for-missing-data/m-p/414187#M279998</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-11-16T23:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: Checking for missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-for-missing-data/m-p/414203#M279999</link>
      <description>&lt;P&gt;Are the variables all the same type, if so what type?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're using EG, I suggest the Characterize data task, its quite useful.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a worked example for generating the number of missing/non missing but I'm not sure thats what you're looking for....&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/2de1faf1644dc8160fe721056202f111" target="_blank"&gt;https://gist.github.com/statgeek/2de1faf1644dc8160fe721056202f111&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 01:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-for-missing-data/m-p/414203#M279999</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-17T01:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Checking for missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-for-missing-data/m-p/414450#M280000</link>
      <description>&lt;P&gt;Here is a modification of &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/6401"&gt;@HB&lt;/a&gt;'s approach:&lt;/P&gt;
&lt;P&gt;Using arrays would require two arrays, one for character and another for numeric variables as an array may not mix types.&lt;/P&gt;
&lt;P&gt;Also since you have largish variable number of variables trying to guess an appropriate size for a single variable to hold all of the names ends up requiring a variable of n*32 + (n-1) characters.&lt;/P&gt;
&lt;P&gt;Since I am assuming that you actually want to read the result then using file print to sent the output to results seems like a practical thing though if you have large numbers of missing variables you may get line wrapping.&lt;/P&gt;
&lt;P&gt;The if statement involving cmiss(of ...) are to restrict output only to the records with any missing&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data one;
input id one two three c1 $;
datalines;
1 9	2	6  abc
2 4	.	3  cds
3 4	9	3  .
4 .	10	.  a
5 0	3	1  b
6 6	.	9  cd
7 4	7	9  e
8 3	8	1  f
9 9	1	5  z
10 0	1	0  .
;
run;

data _null_;
	set one;
   file print;
	array _charvar _character_;
   array _numvar _numeric_;
   if cmiss(of _charvar(*))&amp;gt;0 or cmiss(of _numvar(*)) &amp;gt; 0 then do;
      put "Id: " id @; 
   	do _i_ = 1 to dim(_charvar); 
   		if missing(_charvar[_i_]) then do;
            _varname_= vname(_charvar[_i_]);
            put +1 _varname_ @;
         end;
   	end;
   	do _i_ = 1 to dim(_numvar); 
   		if missing(_numvar[_i_]) then do;
            _varname_= vname(_numvar[_i_]);
            put +1 _varname_ @;
         end;
   	end;
      put;
   end;
run;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Nov 2017 16:10:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-for-missing-data/m-p/414450#M280000</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-17T16:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: Checking for missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-for-missing-data/m-p/414526#M280001</link>
      <description>&lt;P&gt;This works thank you!!&lt;/P&gt;&lt;P&gt;I am not very good with arrays and there are still a lot for me to learn, I really appreciate your wonderful advice to solve my problem!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 20:09:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-for-missing-data/m-p/414526#M280001</guid>
      <dc:creator>michan22</dc:creator>
      <dc:date>2017-11-17T20:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: Checking for missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-for-missing-data/m-p/414563#M280002</link>
      <description>&lt;P&gt;Here is small suggestion that may help with learning one bit about array (or at least the index portion).&lt;/P&gt;
&lt;P&gt;Create a set with no character variables and test the code I provided.&lt;/P&gt;
&lt;P&gt;Then ask why do I not get an error trying to use an array of character variables or do I?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 22:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-for-missing-data/m-p/414563#M280002</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-17T22:51:12Z</dc:date>
    </item>
  </channel>
</rss>

