<?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 Add an observation within a summary dataset to indicated 0 events in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-an-observation-within-a-summary-dataset-to-indicated-0/m-p/645487#M192980</link>
    <description>&lt;P&gt;I am working on writing a program that will produce summary level data by county for a rare event by utilizing a loop macro. The initial dataset I am working out of contains only events, no non-events. I have a rolling 3 year window that is currently summarized by month (within a specific county) by using proc means to get the count by month from the initial dataset, and then outputting the results as a dataset. I then use proc means on the resulting data step in my previous sentence to get the standard deviation of the count by month.&lt;/P&gt;&lt;P&gt;The problem I am running into is that within most counties, this event does not occur each month. So, when I try to use proc means to get the standard deviation it only recognizes the months where the count is at least 1, the standard deviation is wrong as the N does not account for the months missing, as there was no event.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I add an observation to the data set the number of events to 0, so that the standard deviation will be accurate? I want to change the example in 'Current dataset' below, to look like 'Goal dataset'. In my example, month 4 is not in 'Current dataset' as there are 0 events that month. Essentially I want to tell SAS that month 4 is missing so set sum to 0. But, this cannot be hardcoded as it will not always be month 4 that has 0 observations. Note that my actual full dataset includes 36 months, but for interest of space I am only including 6 months below to demonstrate my goal. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Current dataset for county X:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Month &amp;nbsp; Sum&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Goal dataset for county X:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Month &amp;nbsp; Sum&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much in advance!!&lt;/P&gt;</description>
    <pubDate>Wed, 06 May 2020 00:36:56 GMT</pubDate>
    <dc:creator>Khalidbo1</dc:creator>
    <dc:date>2020-05-06T00:36:56Z</dc:date>
    <item>
      <title>Add an observation within a summary dataset to indicated 0 events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-an-observation-within-a-summary-dataset-to-indicated-0/m-p/645487#M192980</link>
      <description>&lt;P&gt;I am working on writing a program that will produce summary level data by county for a rare event by utilizing a loop macro. The initial dataset I am working out of contains only events, no non-events. I have a rolling 3 year window that is currently summarized by month (within a specific county) by using proc means to get the count by month from the initial dataset, and then outputting the results as a dataset. I then use proc means on the resulting data step in my previous sentence to get the standard deviation of the count by month.&lt;/P&gt;&lt;P&gt;The problem I am running into is that within most counties, this event does not occur each month. So, when I try to use proc means to get the standard deviation it only recognizes the months where the count is at least 1, the standard deviation is wrong as the N does not account for the months missing, as there was no event.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I add an observation to the data set the number of events to 0, so that the standard deviation will be accurate? I want to change the example in 'Current dataset' below, to look like 'Goal dataset'. In my example, month 4 is not in 'Current dataset' as there are 0 events that month. Essentially I want to tell SAS that month 4 is missing so set sum to 0. But, this cannot be hardcoded as it will not always be month 4 that has 0 observations. Note that my actual full dataset includes 36 months, but for interest of space I am only including 6 months below to demonstrate my goal. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Current dataset for county X:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Month &amp;nbsp; Sum&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Goal dataset for county X:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Month &amp;nbsp; Sum&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much in advance!!&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2020 00:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-an-observation-within-a-summary-dataset-to-indicated-0/m-p/645487#M192980</guid>
      <dc:creator>Khalidbo1</dc:creator>
      <dc:date>2020-05-06T00:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: Add an observation within a summary dataset to indicated 0 events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-an-observation-within-a-summary-dataset-to-indicated-0/m-p/645491#M192983</link>
      <description>&lt;P&gt;Generate a data set containing all possible county*month crossings and use proc mean's classdata= option.&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2020 00:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-an-observation-within-a-summary-dataset-to-indicated-0/m-p/645491#M192983</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-05-06T00:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: Add an observation within a summary dataset to indicated 0 events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-an-observation-within-a-summary-dataset-to-indicated-0/m-p/645495#M192985</link>
      <description>&lt;P&gt;Try the COMPLETETYPES Option . Here is an example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input country $ month sum;
cards;
country1 1 2
country1 2 1
country1 3 9
country1 4 4
country1 5 0
country1 6 2
country2 2 9
country3 3 1
;
run;

proc means data=have completetypes noprint nway;
	class country  month;
	var sum;
	output out=want(drop=_:) sum= / autoname ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2020 01:35:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-an-observation-within-a-summary-dataset-to-indicated-0/m-p/645495#M192985</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2020-05-06T01:35:06Z</dc:date>
    </item>
    <item>
      <title>Re: Add an observation within a summary dataset to indicated 0 events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-an-observation-within-a-summary-dataset-to-indicated-0/m-p/645515#M192995</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223452"&gt;@r_behata&lt;/a&gt;: your solution needs at least one country that has data for all month that are expected to appear in the result. The completetypes option is useful, if you can attach a format to the variable having all values and use preloadfmt in the class-statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.DummyMonthFmt;
	length FmtName $ 32 Start Label 8;
	
	FmtName = "AllMonth";
	
	do Start = 1 to 12;
		Label = Start;
		output;
	end;
run;

proc format cntlin=work.DummyMonthFmt;
run;

proc means data=have completetypes noprint nway;
	class country month / preloadfmt;
	format month AllMonth.;
	var sum;
	output out=want_c(drop=_:) sum= / autoname ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 May 2020 05:10:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-an-observation-within-a-summary-dataset-to-indicated-0/m-p/645515#M192995</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-05-06T05:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: Add an observation within a summary dataset to indicated 0 events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-an-observation-within-a-summary-dataset-to-indicated-0/m-p/645528#M192999</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327307"&gt;@Khalidbo1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Completetypes options, etc. will work only if the modality occurs at least once in your input dataset.&lt;/P&gt;
&lt;P&gt;For example, if you have no record for month = 11 whatever the country or the year, it will not be added to the output dataset.&lt;/P&gt;
&lt;P&gt;Here is an approach to avoid this trouble.&lt;/P&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input country $ year month sum;
cards;
country1 2018 1 2
country1 2018 2 1
country1 2018 3 9
country1 2018 4 4
country1 2018 6 2
country1 2019 1 2
country1 2019 2 1
country1 2019 3 9
country2 2018 2 9
country2 2018 11 4
country2 2018 2 9
country2 2018 4 9
country2 2018 10 4
country2 2018 11 4
country2 2019 4 9
country2 2019 10 4
country2 2019 11 4
;
run;

data want;
	if _n_=1 then do;
		declare hash h (dataset:"have (rename=(sum=_sum))");
		h.definekey ("country", "year", "month");
		h.definedata ("_sum");
		h.definedone();
	end;
	
	set have;
	by country;
	if first.country then do;
		do year=2017 to 2019; /* &amp;lt;--- specify the years */
			do month = 1 to 12;
				if h.find()=0 then sum = _sum;
				else sum=0;
				output;
			end;
		end;
	end;
	
	drop _sum;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 May 2020 07:16:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-an-observation-within-a-summary-dataset-to-indicated-0/m-p/645528#M192999</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-06T07:16:06Z</dc:date>
    </item>
  </channel>
</rss>

