<?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: Finding the missing values for variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-missing-values-for-variables/m-p/962174#M375041</link>
    <description>&lt;P&gt;You can fully control the contents of a cell if you create a format.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data CARS;
  set SASHELP.CARS;
  if mod(_N_,5) = 0 then LENGTH=.;
  keep ORIGIN TYPE LENGTH;
run;
  
proc sql;
  create table CNT as 
  select a.ORIGIN
       , b.TYPE                 as CARTYPE
       , sum(LENGTH is missing) as M 
       , count(*)               as N 
       , 'miss'                 as FMTNAME
       , 'N'                    as TYPE
       , monotonic()            as OBS
       , case when calculated M = calculated N
              then 'No records'
              else catx(' ', calculated M, 'missing out of' , calculated N, '=', put(calculated M /calculated N, percent.) )            
              end               as LABEL
  from (select unique ORIGIN from CARS) a
         full outer join
       (select unique TYPE   from CARS) b   
         on 1
         left join 
       CARS                             c
         on  a.ORIGIN = c.ORIGIN 
         and b.TYPE   = c.TYPE 
  group by 1, 2;
quit;

proc format cntlin=CNT(rename=(OBS=START));
run;

proc report data=CNT;
  columns CARTYPE ORIGIN, OBS ;
  define CARTYPE / group ;
  define ORIGIN  / across;
  define OBS     / sum format=miss. ' ';
run;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ChrisNZ_0-1742359480768.png" style="width: 492px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105498iA652C04B0B7097FF/image-dimensions/492x190?v=v2" width="492" height="190" role="button" title="ChrisNZ_0-1742359480768.png" alt="ChrisNZ_0-1742359480768.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when calculated M = calculated N&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when missing(c.ORIGIN) | missing(c.TYPE)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but this ruins the &lt;CODE class=" language-sas"&gt;group by&lt;/CODE&gt; operation for some reason.&lt;/P&gt;
&lt;P&gt;If someone knows why...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Mar 2025 05:45:45 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2025-03-19T05:45:45Z</dc:date>
    <item>
      <title>Finding the missing values for variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-missing-values-for-variables/m-p/962156#M375036</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to create&amp;nbsp; a missing table in which one of variables have multiple subcategories. I used this code but it only gives me the overall missing count and I want to see how much is missing in each section including the count and percent .&amp;nbsp; An example of the table I am trying to create is below. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc freq data=work.sleep;&lt;BR /&gt;tables educ*sleep /missing;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;sleep hrs&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;5 hrs&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;6 hrs&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;high school&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;count&amp;nbsp; (%missing)&lt;/TD&gt;&lt;TD&gt;count (%missing)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;college&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;count(%missing)&lt;/TD&gt;&lt;TD&gt;count (%missing)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;graduate&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;count (%missing)&lt;/TD&gt;&lt;TD&gt;count (%missing)&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Mar 2025 01:44:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-missing-values-for-variables/m-p/962156#M375036</guid>
      <dc:creator>coolbeans</dc:creator>
      <dc:date>2025-03-19T01:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the missing values for variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-missing-values-for-variables/m-p/962157#M375037</link>
      <description>Better to post your sample data and desired output to clarify your demand.&lt;BR /&gt;Here 'count' is the count of non-missing obs or missing obs ？ and how do you calculaed %missing  (=a/b  how do you define a and b)?</description>
      <pubDate>Wed, 19 Mar 2025 02:21:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-missing-values-for-variables/m-p/962157#M375037</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-03-19T02:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the missing values for variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-missing-values-for-variables/m-p/962174#M375041</link>
      <description>&lt;P&gt;You can fully control the contents of a cell if you create a format.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data CARS;
  set SASHELP.CARS;
  if mod(_N_,5) = 0 then LENGTH=.;
  keep ORIGIN TYPE LENGTH;
run;
  
proc sql;
  create table CNT as 
  select a.ORIGIN
       , b.TYPE                 as CARTYPE
       , sum(LENGTH is missing) as M 
       , count(*)               as N 
       , 'miss'                 as FMTNAME
       , 'N'                    as TYPE
       , monotonic()            as OBS
       , case when calculated M = calculated N
              then 'No records'
              else catx(' ', calculated M, 'missing out of' , calculated N, '=', put(calculated M /calculated N, percent.) )            
              end               as LABEL
  from (select unique ORIGIN from CARS) a
         full outer join
       (select unique TYPE   from CARS) b   
         on 1
         left join 
       CARS                             c
         on  a.ORIGIN = c.ORIGIN 
         and b.TYPE   = c.TYPE 
  group by 1, 2;
quit;

proc format cntlin=CNT(rename=(OBS=START));
run;

proc report data=CNT;
  columns CARTYPE ORIGIN, OBS ;
  define CARTYPE / group ;
  define ORIGIN  / across;
  define OBS     / sum format=miss. ' ';
run;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ChrisNZ_0-1742359480768.png" style="width: 492px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105498iA652C04B0B7097FF/image-dimensions/492x190?v=v2" width="492" height="190" role="button" title="ChrisNZ_0-1742359480768.png" alt="ChrisNZ_0-1742359480768.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when calculated M = calculated N&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when missing(c.ORIGIN) | missing(c.TYPE)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but this ruins the &lt;CODE class=" language-sas"&gt;group by&lt;/CODE&gt; operation for some reason.&lt;/P&gt;
&lt;P&gt;If someone knows why...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Mar 2025 05:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-missing-values-for-variables/m-p/962174#M375041</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2025-03-19T05:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the missing values for variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-missing-values-for-variables/m-p/962214#M375048</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/472538"&gt;@coolbeans&lt;/a&gt;&amp;nbsp;: If you absolutely have to have text in each cell like "&lt;SPAN&gt;count&amp;nbsp; (%missing)", and if you absolutely have to have redundant titles over the columns,&lt;/SPAN&gt;&amp;nbsp;then your programming will be more complicated and hard, as shown by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If instead you can produce a table that looks something like this (which contains the same information and in my opinion is easier to read)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1742386149983.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105510iC45369FF9D1F7310/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PaigeMiller_0-1742386149983.png" alt="PaigeMiller_0-1742386149983.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then this is a lot easier to produce via PROC REPORT or PROC TABULATE without the complicated SQL. Please provide the information requested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;so that we can provide example code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Mar 2025 12:48:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-missing-values-for-variables/m-p/962214#M375048</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-03-19T12:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the missing values for variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-missing-values-for-variables/m-p/962284#M375075</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;If someone knows why...&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I answer my own question: &lt;/P&gt;
&lt;P&gt;Testing &lt;CODE class=" language-sas"&gt;c.ORIGIN&lt;/CODE&gt; and &lt;CODE class=" language-sas"&gt;c.TYPE&lt;/CODE&gt; assesses observation-level values while testing &lt;CODE class=" language-sas"&gt;calculated M&lt;/CODE&gt; and &lt;CODE class=" language-sas"&gt;calculated N&lt;/CODE&gt; assesses summarised values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Adding a presence flag to see whether a record is prsent&amp;nbsp; computes the counts properly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  retain FLG 1;
  set SASHELP.CARS;
  if mod(_N_,5) = 0               then LENGTH=.;
  if ORIGIN='Asia' and TYPE='SUV' then LENGTH=.;
run;
  
proc sql;
  create table COUNTS as 
  select a.ORIGIN
       , b.TYPE                 as CARTYPE
       , sum(LENGTH is missing) as M 
       , count(*)               as N 
       , 'miss'                 as FMTNAME
       , 'N'                    as TYPE
       , monotonic()            as OBS
       , case when sum(FLG) &amp;lt; 1
              then 'No records'
              else catx(' ', calculated M, 'missing out of' , calculated N, '=', put(calculated M /calculated N, percent.) )            
              end               as LABEL
  from (select unique ORIGIN from HAVE) a
         full outer join
       (select unique TYPE   from HAVE) b   
         on 1
         left join 
       HAVE                             c
         on  a.ORIGIN = c.ORIGIN 
         and b.TYPE   = c.TYPE 
  group by 1, 2;
quit;

proc format cntlin=COUNTS(rename=(OBS=START));
run;

proc report data=COUNTS;
  columns CARTYPE ORIGIN, OBS;
  define CARTYPE / group ;
  define ORIGIN  / across;
  define OBS     / sum format=miss. ' ';
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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Mar 2025 22:28:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-missing-values-for-variables/m-p/962284#M375075</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2025-03-19T22:28:45Z</dc:date>
    </item>
  </channel>
</rss>

