<?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: how to count multiple observations within different time period segments in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-count-multiple-observations-within-different-time-period/m-p/572954#M161713</link>
    <description>&lt;P&gt;Do your intervals overlap? This is what PROC MEANS is designed for essentially, but there are ways to do this within a SQL query as well.&amp;nbsp; In a perfect world you can show an example input, expected output and what you've tried. Please included as much of that as possible. This can definitely be done in one or two steps in SAS.&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jul 2019 21:34:03 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-07-11T21:34:03Z</dc:date>
    <item>
      <title>how to count multiple observations within different time period segments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-count-multiple-observations-within-different-time-period/m-p/572951#M161712</link>
      <description>&lt;P&gt;Hello, I am first time user of this board.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have database that contains the 4 types of materials used over the last 100 years.&lt;/P&gt;&lt;P&gt;I like to make a table that shows how many of those 4 materials were used in 5 yrs time segment.&lt;/P&gt;&lt;P&gt;For example, I like to say between 1958-1962, material A was used 100 times, B 50 times, C 10 times, and D 40 times etc.&lt;/P&gt;&lt;P&gt;I am using proc sql to count observation, but it's so hard as I have to repeat the same command over 100 times.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data look like this;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Address&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Year_of_service&amp;nbsp; &amp;nbsp; &amp;nbsp; Material_used&lt;/P&gt;&lt;P&gt;113 cascade&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&lt;/P&gt;&lt;P&gt;11 stonehill&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1963&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B&lt;/P&gt;&lt;P&gt;10 bushes&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1953&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C&lt;/P&gt;&lt;P&gt;114 oat mil&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1993&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have about 10,000 observations.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently using this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select count(*) as N_Obs&lt;BR /&gt;from sort1&lt;BR /&gt;where Material_used="A" and Year_of_service&amp;gt;1962 and Year_of_service &amp;lt;1968&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 21:37:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-count-multiple-observations-within-different-time-period/m-p/572951#M161712</guid>
      <dc:creator>hpark</dc:creator>
      <dc:date>2019-07-11T21:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to count multiple observations within different time period segments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-count-multiple-observations-within-different-time-period/m-p/572954#M161713</link>
      <description>&lt;P&gt;Do your intervals overlap? This is what PROC MEANS is designed for essentially, but there are ways to do this within a SQL query as well.&amp;nbsp; In a perfect world you can show an example input, expected output and what you've tried. Please included as much of that as possible. This can definitely be done in one or two steps in SAS.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 21:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-count-multiple-observations-within-different-time-period/m-p/572954#M161713</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-11T21:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to count multiple observations within different time period segments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-count-multiple-observations-within-different-time-period/m-p/572956#M161714</link>
      <description>&lt;P&gt;Concrete examples of data usually help. Especially how to show something like "material A was used".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best is to provide an example in the form of a data step that we can run to create example data to work with as that answers lots of questions about such things as data variable names and types.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or at least show one example of your SQL code that works.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 21:41:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-count-multiple-observations-within-different-time-period/m-p/572956#M161714</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-11T21:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: how to count multiple observations within different time period segments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-count-multiple-observations-within-different-time-period/m-p/572957#M161715</link>
      <description>&lt;P&gt;It's a good case for applying a format, and letting PROC FREQ do the counting&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data groups;
   do start = 1919 to 2014 by 5;
      end = start + 4;
      label = cats (start, '-', end);
      output;
   end;
   retain fmtname 'group_yr';
end;

proc format cntlin = groups;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That gives you a format capable of grouping into 5-year increments.&amp;nbsp; Then apply the format while counting:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
   tables year_of_service * material_used / norow nocol nopercent;
   format year_of_service group_yr.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 21:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-count-multiple-observations-within-different-time-period/m-p/572957#M161715</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-07-11T21:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to count multiple observations within different time period segments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-count-multiple-observations-within-different-time-period/m-p/572959#M161716</link>
      <description>&lt;P&gt;Or if you have un-even intervals of interest you can specify them as well such as:&lt;/P&gt;
&lt;PRE&gt;proc format ;
value someinterval
  1900 - 1929 = '1900-1929'
  1930 - 1955 = '1930-1955'
  1956 - 1999 = '1940-1999'
  2000 - high = '2000 and later'
;
run;
&lt;/PRE&gt;
&lt;P&gt;The only change in the Proc freq code would be the format assigned to the YEAR variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also create related groups of the material.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LOTS of things can be done with formats and some procedures: Tabulate Summary and Means support a more complex format type called MULTILABEL that can create subgroups as well such as a total for Years 1900-1950, 1951-1975, 1976-2005&amp;nbsp;then by subgroups within each range.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 22:10:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-count-multiple-observations-within-different-time-period/m-p/572959#M161716</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-11T22:10:28Z</dc:date>
    </item>
  </channel>
</rss>

