<?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 Percent Missing List in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Percent-Missing-List/m-p/350100#M273608</link>
    <description>&lt;P&gt;I have a large survey data set with hundreds of variables, both numeric and character. &amp;nbsp;Each variable can take two missing values, M or N. &amp;nbsp;I want to make a list that shows the percent of M values for each variable. &amp;nbsp;I can define formats to collapse all the variables into M and not-M, but I'm stuck at producing the list. &amp;nbsp;With this many variables, hand-coding is out of the question. &amp;nbsp;I thought to make an output dataset with PROC FREQ, but that allows only one frequency distribution per output dataset. &amp;nbsp;The regular output from PROC FREQ contains all the headers, which I don't want to have to edit out. &amp;nbsp;I've also tried PROC TABULATE, but I can't work out how to get it to do what I want. &amp;nbsp;I could set up a macro to loop through each variable, run PROC FREQ, and concatenate the output datasets. &amp;nbsp;However, I feel like there must be a smack-in-the-head-of-course method that I'm missing. &amp;nbsp;What is it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want a list like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Variable Name &amp;nbsp; &amp;nbsp;Percent M.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;--Dav&lt;/P&gt;</description>
    <pubDate>Fri, 14 Apr 2017 17:18:01 GMT</pubDate>
    <dc:creator>Davanden</dc:creator>
    <dc:date>2017-04-14T17:18:01Z</dc:date>
    <item>
      <title>Percent Missing List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-Missing-List/m-p/350100#M273608</link>
      <description>&lt;P&gt;I have a large survey data set with hundreds of variables, both numeric and character. &amp;nbsp;Each variable can take two missing values, M or N. &amp;nbsp;I want to make a list that shows the percent of M values for each variable. &amp;nbsp;I can define formats to collapse all the variables into M and not-M, but I'm stuck at producing the list. &amp;nbsp;With this many variables, hand-coding is out of the question. &amp;nbsp;I thought to make an output dataset with PROC FREQ, but that allows only one frequency distribution per output dataset. &amp;nbsp;The regular output from PROC FREQ contains all the headers, which I don't want to have to edit out. &amp;nbsp;I've also tried PROC TABULATE, but I can't work out how to get it to do what I want. &amp;nbsp;I could set up a macro to loop through each variable, run PROC FREQ, and concatenate the output datasets. &amp;nbsp;However, I feel like there must be a smack-in-the-head-of-course method that I'm missing. &amp;nbsp;What is it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want a list like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Variable Name &amp;nbsp; &amp;nbsp;Percent M.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;--Dav&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2017 17:18:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-Missing-List/m-p/350100#M273608</guid>
      <dc:creator>Davanden</dc:creator>
      <dc:date>2017-04-14T17:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: Percent Missing List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-Missing-List/m-p/350128#M273609</link>
      <description>&lt;P&gt;Some example data would be helpful. You may end up going back to re-reading your raw data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS has more than one "missing" actually a single variable can have up to 27 different missing values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a brief example of recoding values to the missing for numeric values.&lt;/P&gt;
&lt;PRE&gt;data example;
   input q1 q2 q3;
   /* assume questions q1 through 3 are coded the same
   and a recorded respose of 77 means "Don't know"
   and 99 is "Refused"*/
   array q q1-q3;
   do i=1 to dim(q);
      if q[i]= 77 then q[i]= .D;
      if q[i]= 99 then q[i]= .R;
   end;

datalines;
1 2 77
2 3 1
99 4 3
1 . 2
;
run;

proc freq data=example;
   tables q1 q2 q3 ;
run;
proc format library=work;
value myq
.D= "Don't Know"
.R= "Refused"
. = "No Answer"
;
run;

proc freq data=example;
   tables q1 q2 q3/missing ;
   format q: myq.; 
run;

proc tabulate data=example;
   class q1 q2 q3/missing;
   format q1 q2 q3 myq.;
   tables q1 q2 q3, n pctn;
run;&lt;/PRE&gt;
&lt;P&gt;If you need to do the exact same thing to all of the numeric variables you can use: Array arrayname _numeric_; which places all of the numeric variables into the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Same with character variables:&lt;/P&gt;
&lt;P&gt;Array charvars _character_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For anything else you should provide some concrete input data and what the result from that data is expected.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2017 18:25:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-Missing-List/m-p/350128#M273609</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-14T18:25:33Z</dc:date>
    </item>
    <item>
      <title>Re: Percent Missing List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-Missing-List/m-p/350174#M273610</link>
      <description>&lt;P&gt;(a) are your variables character (possibly with a value of "M") or numeric (possibly with a value of .M)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(b) when computing percentages, do you want all non-M values (including missing values) included in the denominator?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The programming isn't that difficult, but I need the answers first.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2017 19:43:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-Missing-List/m-p/350174#M273610</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-14T19:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: Percent Missing List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-Missing-List/m-p/350227#M273611</link>
      <description>&lt;P&gt;"&lt;SPAN&gt; both numeric and character. &amp;nbsp;Each variable can take two missing values, M or N."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Show us the sample data and the output you are looking for .&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input a $ b;
cards;
M 12
c .M
x .N
n .M
;
run;

data _null_;
 set sashelp.vcolumn(keep=libname memname name type
 where=(upcase(libname)='WORK' and upcase(memname)='HAVE')) end=last;
 if _n_=1 then call execute('proc sql;create table temp as select ');
 if type='char' then call execute(cat('sum(',name,'="M")/count(*) as ',name));
  else call execute(cat('sum(',name,'=.M)/count(*) as ',name));
 if last then call execute('from have;quit;');
  else call execute(',');
run;
proc transpose data=temp out=want;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 15 Apr 2017 03:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-Missing-List/m-p/350227#M273611</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-04-15T03:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: Percent Missing List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-Missing-List/m-p/350485#M273612</link>
      <description>&lt;P&gt;Thanks to everyone who replied. &amp;nbsp;I am aware that SAS variables can take multiple missing values, and that there is a difference in the way they are treated for numeric an character variables. &amp;nbsp;In my case, I have both character and numeric variables. &amp;nbsp;For character variables, missing values are indcated by 'M' or 'N'; for numeric, .M or .N. &amp;nbsp;I want to list the percentage of &lt;EM&gt;all&lt;/EM&gt; cases that have the 'M' or .M value, as applicable, for every variable, of which there are a great many. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For a totally made-up example, see the pictures below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/8345iC4FBB21C298A50F1/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="have.PNG" title="have.PNG" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/8346iF47DEEC6E33735D4/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="want.PNG" title="want.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 12:50:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-Missing-List/m-p/350485#M273612</guid>
      <dc:creator>Davanden</dc:creator>
      <dc:date>2017-04-17T12:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: Percent Missing List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-Missing-List/m-p/350492#M273613</link>
      <description>&lt;PRE&gt;
So did you try my code ?


&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Apr 2017 13:18:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-Missing-List/m-p/350492#M273613</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-04-17T13:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: Percent Missing List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-Missing-List/m-p/350495#M273614</link>
      <description>&lt;P&gt;Yes, I did. &amp;nbsp;It does work. &amp;nbsp;Thank you for your help. &amp;nbsp;My pride is assuaged by the fact that it was not as simple and obvious as I had feared.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;--Dav&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 13:41:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-Missing-List/m-p/350495#M273614</guid>
      <dc:creator>Davanden</dc:creator>
      <dc:date>2017-04-17T13:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: Percent Missing List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-Missing-List/m-p/350703#M273615</link>
      <description>&lt;PRE&gt;
if you want simpler, IML code might do it .

&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Apr 2017 04:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-Missing-List/m-p/350703#M273615</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-04-18T04:52:27Z</dc:date>
    </item>
  </channel>
</rss>

