<?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: proc tabulate -number of obs with non missing value in ID value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-number-of-obs-with-non-missing-value-in-ID-value/m-p/540445#M149094</link>
    <description>&lt;P&gt;Your request:&lt;/P&gt;
&lt;PRE&gt;I want to calculate number of observations only for non missing values of ID var&lt;/PRE&gt;
&lt;P&gt;assuming that proc tabulate should ignore those observation you can do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=want(where=(ID ne .)) ....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but then other variables of those observation will be ignored too.&lt;/P&gt;</description>
    <pubDate>Tue, 05 Mar 2019 14:07:08 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2019-03-05T14:07:08Z</dc:date>
    <item>
      <title>proc tabulate -number of obs with non missing value in ID value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-number-of-obs-with-non-missing-value-in-ID-value/m-p/540413#M149078</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;In proc tabulate I am using "N" stastistics to calculate number of observations in each category.&lt;/P&gt;
&lt;P&gt;However in this example I want to calculate&amp;nbsp;number of observations only for non missing values of ID var .&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data rawdata;
input ID  Ddate  Ind  Y;
cards;
1 1806 1 100
1 1807 1 200
1 1809 1 300
2 1809 1 400
2 1807 1 500
2 1806 2 600
2 1806 2 700
3 1805 3 800
3 1805 3 900
4 1805 3 100
5 1802 3 110
6 1802 3 120
7 1802 4 130
;
run;

%let minDdate=1801;
%let MaxDdate=1810;
%put &amp;amp;minDdate;
%put &amp;amp;MaxDdate;


%let minInd=1;
%let MaxInd=4;
%put &amp;amp;minInd;
%put &amp;amp;MaxInd;


%let date_MinDdate=%sysfunc(inputn(&amp;amp;MinDdate.,yymmn4.));
%let date_MaxDdate=%sysfunc(inputn(&amp;amp;MaxDdate.,yymmn4.));
%put &amp;amp;date_MinDdate.  ;
%put &amp;amp;date_MaxDdate. 


data _null_;
No=intck('month',&amp;amp;date_MinDdate.,&amp;amp;date_MaxDdate.);
call symput("No",trim(left(No)));
run;
%put &amp;amp;No;



%macro mmacro1;
%do i=0 %to &amp;amp;No.;
%do j=&amp;amp;minInd. %to &amp;amp;MaxInd.;
	Ddate=put(intnx('month',&amp;amp;date_MinDdate.,&amp;amp;i.),yymmn4.)*1;
	ind =&amp;amp;j.;
	output;
%end;
%end;
%mend mmacro1;

/*כל הצירופים האפשריים של הקטגוריות*/
data Sheled;
%mmacro1;
run;


proc sql;
	create table want as 
		select ID ,
			coalesce(a.Ddate, b.Ddate) as Ddate,
			coalesce(a.Ind, b.Ind) as Ind,
			coalesce(a.Y,0) as Y
		from rawdata as a
        full outer join Sheled as b 
		on a.Ind = b.Ind  and a.Ddate = b.Ddate
        order by calculated Ddate,calculated Ind
;
quit;


 
/*Correct  OUTCOME*/
PROC TABULATE DATA=want ;
    var Y;
	CLASS Ind /	ORDER=UNFORMATTED MISSING;
	CLASS Ddate /	ORDER=UNFORMATTED MISSING;
 	TABLE Ind="" ALL={LABEL="Total"},
			Ddate=''*Y=''*SUM=''*f=zeromiss. 
			Y=''*SUM='Total'
          /box='Indicator';
RUN;
 

/*wrong OUTCOME*/
PROC TABULATE DATA=want ;
    var Y;
	CLASS Ind /	ORDER=UNFORMATTED MISSING;
	CLASS Ddate /	ORDER=UNFORMATTED MISSING;
 	TABLE Ind="" ALL={LABEL="Total"},
			Ddate=''*Y=''*N=''*f=zeromiss. 
			Y=''*N='Total'
          /box='Indicator';
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>Tue, 05 Mar 2019 11:57:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-number-of-obs-with-non-missing-value-in-ID-value/m-p/540413#M149078</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-03-05T11:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate -number of obs with non missing value in ID value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-number-of-obs-with-non-missing-value-in-ID-value/m-p/540445#M149094</link>
      <description>&lt;P&gt;Your request:&lt;/P&gt;
&lt;PRE&gt;I want to calculate number of observations only for non missing values of ID var&lt;/PRE&gt;
&lt;P&gt;assuming that proc tabulate should ignore those observation you can do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=want(where=(ID ne .)) ....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but then other variables of those observation will be ignored too.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2019 14:07:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-number-of-obs-with-non-missing-value-in-ID-value/m-p/540445#M149094</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-03-05T14:07:08Z</dc:date>
    </item>
  </channel>
</rss>

