<?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: Counting the number of observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318387#M69754</link>
    <description>&lt;P&gt;See example 2 in this paper:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi30/001-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/001-30.pdf&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Dec 2016 21:39:15 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-12-12T21:39:15Z</dc:date>
    <item>
      <title>Counting the number of observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318381#M69750</link>
      <description>&lt;P&gt;Hello SAS community!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to do a simple analysis of one dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's say there are 2 variable A and B.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to know how many observations not missing variable A or B are in my dataset. Also, I want to know the number of observation missing value for A but not for B and vice versa.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What would be good a way to see this? Thank you very much &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2016 21:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318381#M69750</guid>
      <dc:creator>Leon_Seungmin</dc:creator>
      <dc:date>2016-12-12T21:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318384#M69752</link>
      <description>&lt;P&gt;The coding would be slightly different for numeric vs. character variables.&amp;nbsp; What are we dealing with here?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2016 21:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318384#M69752</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-12T21:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318385#M69753</link>
      <description>&lt;P&gt;Right now, I am dealing with character variables but it would be nice to know how to deal with numaric variables as well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2016 21:36:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318385#M69753</guid>
      <dc:creator>Leon_Seungmin</dc:creator>
      <dc:date>2016-12-12T21:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318387#M69754</link>
      <description>&lt;P&gt;See example 2 in this paper:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi30/001-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/001-30.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2016 21:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318387#M69754</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-12T21:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318388#M69755</link>
      <description>&lt;P&gt;If the data is not really complicated or large I tend to start with something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc freq data=have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables a * b /list missing;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the result could be sent to a data set using the OUT= option.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2016 21:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318388#M69755</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-12T21:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318396#M69758</link>
      <description>&lt;P&gt;Assuming you create the formats along the lines mentioned in Reeza's reference, the complete program could be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format;&lt;/P&gt;
&lt;P&gt;value $miss ' '='Missing' other='Present';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=have;&lt;/P&gt;
&lt;P&gt;tables a * b / list missing;&lt;/P&gt;
&lt;P&gt;format a b $miss.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2016 22:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318396#M69758</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-12T22:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318715#M69862</link>
      <description>&lt;P&gt;Thanks for the advice. However, the results were bit different from what I expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dataset has more than 1 million observation and this program lists all list of observation under variable A and B.&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Count if A = missing&lt;/P&gt;&lt;P&gt;Count if B = missing&lt;/P&gt;&lt;P&gt;Count if A = missing &amp;amp; B =! missing&lt;/P&gt;&lt;P&gt;Count if B&amp;nbsp;= missing &amp;amp; A&amp;nbsp;=! missing&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to see one number for each of these 4 conditions something like 3,482 for the number of A having no observation&lt;/P&gt;&lt;P&gt;and 1,923 for observation missing A but having info about B.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would appreciate if you can help me with this!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 22:05:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318715#M69862</guid>
      <dc:creator>Leon_Seungmin</dc:creator>
      <dc:date>2016-12-13T22:05:02Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318720#M69866</link>
      <description>&lt;P&gt;Did you try the example code.&lt;/P&gt;
&lt;P&gt;Once you've assigned the formats and cross any variables you should get only Missing vs Not Missing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post what you've tried.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 22:22:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318720#M69866</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-13T22:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318722#M69867</link>
      <description>&lt;P&gt;Thanks for the response! I have a few additional questions.&lt;/P&gt;&lt;P&gt;The following is the result I got from running the program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS Output&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV align="left"&gt;COMPANY_FKEY SIC_CODE_FKEY Frequency Percent Cumulative&lt;BR /&gt;Frequency Cumulative&lt;BR /&gt;Percent Present Missing Present Present &lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;52&lt;/TD&gt;&lt;TD&gt;0.32&lt;/TD&gt;&lt;TD&gt;52&lt;/TD&gt;&lt;TD&gt;0.32&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;16412&lt;/TD&gt;&lt;TD&gt;99.68&lt;/TD&gt;&lt;TD&gt;16464&lt;/TD&gt;&lt;TD&gt;100.00&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran the program on a sample dataset and I wasn't sure how to interpret this. It appears that there are 52 firm-year observations that does not have SIC_CODE_FKEY while they have COMPANY_FKEY. However, even when I changed the order of the variable, it did not show the other case which is missing COMPANY_FKEY and having SIC_CODE_FKEY.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, is it possible to know all 4 possible scenarios? 1) having both A &amp;amp; B 2) having only A 3) having only B 4) missing both A &amp;amp; B&lt;/P&gt;&lt;P&gt;and list the observation for each case?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the help!&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 13 Dec 2016 22:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318722#M69867</guid>
      <dc:creator>Leon_Seungmin</dc:creator>
      <dc:date>2016-12-13T22:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318724#M69869</link>
      <description>&lt;P&gt;Thanks Reeza for sharing the file!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I read the example 2, but I am not quite familiar with SAS, I was not sure how to apply this to my case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To be bit more specific, two variables of interest are&amp;nbsp;COMPANY_FKEY and&amp;nbsp;BEST_EDGAR_TICKER. In the file you gave me,&amp;nbsp;&lt;/P&gt;&lt;P&gt;the following example is given. The library I am using is&amp;nbsp;cleaning.cleanrestat.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value $ missfmt ' '="Missing"
other="Not Missing"
;
value nmissfmt . ="Missing"
other="Not Missing"
;
run;
proc freq data=home.ex2;
tables _numeric_ _character_/missing;
format _numeric_ nmissfmt.
_character_ $missfmt.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Once again, I am not quite familiar with SAS yet, I was trying to figure out which one is statement and which one is name of the variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you can help me with this one, that will be very kind of you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another thing I noticed in the example is that the output only shows the number of observation missing and not missing only for each variable. I want to know the number of observation missing A but not B. It would be also nice if you can help me add that condition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 22:30:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318724#M69869</guid>
      <dc:creator>Leon_Seungmin</dc:creator>
      <dc:date>2016-12-13T22:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318733#M69871</link>
      <description>&lt;P&gt;If it's only about two variables then some cross tabulation as already posted should do. If you want to list the missing/non missing combinations of n variables then you could also create a single new variable which contains a 0 for missing an a 1 for a value per source variable and then create a count of this single variable. See sample code below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  set sashelp.cars (keep= Make Model EngineSize Cylinders);
  /* create some missing values */
  if mod(ceil(ranuni(1)*20),5)=0 then call missing(Make);
  if mod(ceil(ranuni(1)*20),5)=0 then call missing(Model);
  if mod(ceil(ranuni(1)*20),5)=0 then call missing(EngineSize);
  if mod(ceil(ranuni(1)*20),5)=0 then call missing(Cylinders);
run;

data prep(keep=Miss0_NoMiss1);
  set have;
  length Miss0_NoMiss1 $ 4;
  Miss0_NoMiss1=cats(not missing(Make),not missing(Model),not missing(EngineSize),not missing(Cylinders));
run;

proc freq data=prep;
  table Miss0_NoMiss1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Dec 2016 23:31:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318733#M69871</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-12-13T23:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318736#M69873</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;format&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;value&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt; missfmt &lt;SPAN class="token string"&gt;' '&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"Missing"&lt;/SPAN&gt;
other&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"Not Missing"&lt;/SPAN&gt;
&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;value&lt;/SPAN&gt; nmissfmt &lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"Missing"&lt;/SPAN&gt;
other&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"Not Missing"&lt;/SPAN&gt;
&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;freq&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;home&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;ex&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; VARIABLE1*VARIABLE2&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;missing&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;format&lt;/SPAN&gt; _numeric_ nmissfmt&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;
_character_ &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;missfmt&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the A*B cross tab, you can use an asterisk between the variables in the TABLE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can see the example above, where I assume VARIABLE1= &amp;lt;your variable name&amp;gt; and VARIABLE2 = &amp;lt;your variable name&amp;gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 00:55:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-observation/m-p/318736#M69873</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-14T00:55:30Z</dc:date>
    </item>
  </channel>
</rss>

