<?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: Aggregating data from individual to census tract within date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746047#M233984</link>
    <description>&lt;P&gt;Here is the log:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;138&lt;BR /&gt;139 proc sql;&lt;BR /&gt;140 create table sqfagg as&lt;BR /&gt;141 select sqfmthyr, tract2010, count (*) as stopcount, sum(frisk) as friskcount&lt;BR /&gt;141! format=comma10. , sum(furtive) as furtcount format=comma10. ,&lt;BR /&gt;142 sum(search) as searchcount format=comma10. , sum(arrestmade) as arrestcount&lt;BR /&gt;142! format=comma10.,&lt;BR /&gt;143 sum(summonissue) as summonscount format=comma10., sum(physicalforce) as phyfrc&lt;BR /&gt;143! format=comma10.,&lt;BR /&gt;144 sum(criminaldress) format=comma10. as crimdress&lt;BR /&gt;145 from sqfmonthyear&lt;BR /&gt;146 group by tract2010, sqfmthyr ;&lt;BR /&gt;NOTE: Table WORK.SQFAGG created, with 1656327 rows and 10 columns.&lt;/P&gt;&lt;P&gt;147 quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 1.46 seconds&lt;BR /&gt;cpu time 1.42 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It shows as if it is working without errors, but I should only have ~200K rows of data if it aggregates correctly&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 05 Jun 2021 21:52:30 GMT</pubDate>
    <dc:creator>casmcfarland</dc:creator>
    <dc:date>2021-06-05T21:52:30Z</dc:date>
    <item>
      <title>Aggregating data from individual to census tract within date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746043#M233980</link>
      <description>&lt;P&gt;I am trying to create an aggregate dataset that will have a count of every time a person was stopped, frisked, etc within a census tract within a given month/year. Here is the code I am using and I should be going from 4 million cases to approximately 200K but it is not working and it is aggregating some but not all, so I still have duplicate month/year within census tracts instead of the sum of stops, etc. Please help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=sqfmonthyear;&lt;BR /&gt;by tract2010 sqfmthyr ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table sqfagg as&lt;BR /&gt;select sqfmthyr, tract2010, count (*) as stopcount; sum(frisk) as friskcount format=comma10. , sum(furtive) as furtcount format=comma10. ,&lt;BR /&gt;sum(search) as searchcount format=comma10. , count(*) as stopcount format=comma10., sum(arrestmade) as arrestcount format=comma10.,&lt;BR /&gt;sum(summonissue) as summonscount format=comma10., sum(physicalforce) as phyfrc format=comma10.,&lt;BR /&gt;sum(criminaldress) format=comma10. as crimdress&lt;BR /&gt;from sqfmonthyear&lt;BR /&gt;group by tract2010, sqfmthyr ;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Jun 2021 21:40:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746043#M233980</guid>
      <dc:creator>casmcfarland</dc:creator>
      <dc:date>2021-06-05T21:40:07Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating data from individual to census tract within date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746045#M233982</link>
      <description>&lt;P&gt;What is not working about this? Show us.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is an error in the LOG, please SHOW US the log, showing the entire log for PROC SQL (we need to see the entire PROC SQL code as it appears in the log and we need to see the NOTEs and ERRORs and WARNINGs, with nothing chopped out, every single character)&lt;/P&gt;</description>
      <pubDate>Sat, 05 Jun 2021 21:50:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746045#M233982</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-05T21:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating data from individual to census tract within date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746047#M233984</link>
      <description>&lt;P&gt;Here is the log:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;138&lt;BR /&gt;139 proc sql;&lt;BR /&gt;140 create table sqfagg as&lt;BR /&gt;141 select sqfmthyr, tract2010, count (*) as stopcount, sum(frisk) as friskcount&lt;BR /&gt;141! format=comma10. , sum(furtive) as furtcount format=comma10. ,&lt;BR /&gt;142 sum(search) as searchcount format=comma10. , sum(arrestmade) as arrestcount&lt;BR /&gt;142! format=comma10.,&lt;BR /&gt;143 sum(summonissue) as summonscount format=comma10., sum(physicalforce) as phyfrc&lt;BR /&gt;143! format=comma10.,&lt;BR /&gt;144 sum(criminaldress) format=comma10. as crimdress&lt;BR /&gt;145 from sqfmonthyear&lt;BR /&gt;146 group by tract2010, sqfmthyr ;&lt;BR /&gt;NOTE: Table WORK.SQFAGG created, with 1656327 rows and 10 columns.&lt;/P&gt;&lt;P&gt;147 quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 1.46 seconds&lt;BR /&gt;cpu time 1.42 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It shows as if it is working without errors, but I should only have ~200K rows of data if it aggregates correctly&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Jun 2021 21:52:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746047#M233984</guid>
      <dc:creator>casmcfarland</dc:creator>
      <dc:date>2021-06-05T21:52:30Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating data from individual to census tract within date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746048#M233985</link>
      <description>&lt;P&gt;Did you look at the output data set sqfagg to see what was incorrect in there? Please do that. See what is wrong, and then SHOW US and explain further.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since we don't have your data, please provide a small portion of your data (or make up some data) following &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt;. Please, for this small portion of the data, indicate what you think the correct answers are.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Jun 2021 22:03:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746048#M233985</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-05T22:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating data from individual to census tract within date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746050#M233986</link>
      <description>&lt;P&gt;You have an extra semicolon after your first sum.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's probably causing issues, but it's not in your log so something isn't lining up here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whats the format and type of variable &lt;SPAN&gt;sqfmthyr? If it's a date, it will aggregate at a daily level regardless of formats, SQL doesn't honour SAS formats when aggregating. If that's the case, you can convert it with a PUT() function or use PROC MEANS or REPORT or TABULATE to generate a nice clean table. I'd probably recommend the latter personally but it&amp;nbsp;does depend on a few things.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/384582"&gt;@casmcfarland&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to create an aggregate dataset that will have a count of every time a person was stopped, frisked, etc within a census tract within a given month/year. Here is the code I am using and I should be going from 4 million cases to approximately 200K but it is not working and it is aggregating some but not all, so I still have duplicate month/year within census tracts instead of the sum of stops, etc. Please help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=sqfmonthyear;&lt;BR /&gt;by tract2010 sqfmthyr ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table sqfagg as&lt;BR /&gt;select sqfmthyr, tract2010, count (*) as stopcount; sum(frisk) as friskcount format=comma10. , sum(furtive) as furtcount format=comma10. ,&lt;BR /&gt;sum(search) as searchcount format=comma10. , count(*) as stopcount format=comma10., sum(arrestmade) as arrestcount format=comma10.,&lt;BR /&gt;sum(summonissue) as summonscount format=comma10., sum(physicalforce) as phyfrc format=comma10.,&lt;BR /&gt;sum(criminaldress) format=comma10. as crimdress&lt;BR /&gt;from sqfmonthyear&lt;BR /&gt;group by tract2010, sqfmthyr ;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Jun 2021 23:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746050#M233986</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-05T23:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating data from individual to census tract within date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746055#M233988</link>
      <description>&lt;P&gt;&lt;BR /&gt;138&lt;BR /&gt;139 proc sql;&lt;BR /&gt;140 create table sqfagg as&lt;BR /&gt;141 select sqfmthyr, tract2010, count (*) as stopcount, sum(frisk) as friskcount&lt;BR /&gt;141! format=comma10. , sum(furtive) as furtcount format=comma10. ,&lt;BR /&gt;142 sum(search) as searchcount format=comma10. , sum(arrestmade) as arrestcount&lt;BR /&gt;142! format=comma10.,&lt;BR /&gt;143 sum(summonissue) as summonscount format=comma10., sum(physicalforce) as phyfrc&lt;BR /&gt;143! format=comma10.,&lt;BR /&gt;144 sum(criminaldress) format=comma10. as crimdress&lt;BR /&gt;145 from sqfmonthyear&lt;BR /&gt;146 group by tract2010, sqfmthyr ;&lt;BR /&gt;NOTE: Table WORK.SQFAGG created, with 1656327 rows and 10 columns.&lt;/P&gt;&lt;P&gt;147 quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 1.46 seconds&lt;BR /&gt;cpu time 1.42 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry, this is the first time I have asked a question. SQFMTHYR is a date (date YYYYMM format)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the data, the first three rows should have been combined in the sum/count, so stopcount=3, friskcount=2, summonscount=1, phyfrc=3, other variables=0.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="casmcfarland_0-1622939963563.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60056iA2B3EE4A52716A00/image-size/large?v=v2&amp;amp;px=999" role="button" title="casmcfarland_0-1622939963563.png" alt="casmcfarland_0-1622939963563.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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jun 2021 00:41:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746055#M233988</guid>
      <dc:creator>casmcfarland</dc:creator>
      <dc:date>2021-06-06T00:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating data from individual to census tract within date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746056#M233989</link>
      <description>&lt;P&gt;Yeah, I think you're definitely running into the date issue then. You need to either use PUT() or convert to PROC MEANS. &lt;BR /&gt;&lt;BR /&gt;Please don't post your data as images. We can't work with an image and then to test your code we'd have to type it out. It's not really helpful. Also, please post your code in a code box, not as free text. It loses all formatting that way. &lt;BR /&gt;&lt;BR /&gt;You don't need to presort for SQL. &lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table sqfagg as
select put(sqfmthyr, YYYYMM6.) as reporting_period,
 tract2010, count (*) as stopcount,
 sum(frisk) as friskcount format=comma10. , 
sum(furtive) as furtcount format=comma10. ,
sum(search) as searchcount format=comma10. , 
count(*) as stopcount format=comma10., 
sum(arrestmade) as arrestcount format=comma10.,
sum(summonissue) as summonscount format=comma10., 
sum(physicalforce) as phyfrc format=comma10.,
sum(criminaldress) format=comma10. as crimdress

from sqfmonthyear

group by tract2010, put(sqfmthyr, YYYYMM6.) ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If this doesn't work please post the log from this code.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jun 2021 00:57:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746056#M233989</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-06T00:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating data from individual to census tract within date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746065#M233996</link>
      <description>&lt;P&gt;Can you show some of the data that you believe should have been aggregated but is not?&amp;nbsp; It's hard to picture without a few examples.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jun 2021 05:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746065#M233996</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-06T05:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating data from individual to census tract within date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746069#M234000</link>
      <description>&lt;P&gt;When you run &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;'s code, look at the log. If you get a NOTE about remerging, change the GROUP BY clause to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;group by tract2010, calculated reporting_period&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But it might be that the syntax as posted already avoids the automatic remerge.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jun 2021 07:23:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746069#M234000</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-06T07:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating data from individual to census tract within date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746382#M234134</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/384582"&gt;@casmcfarland&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;You are grouping by only 2 variables. We need to verify if it is possible to reduce to 200K rows and not the result you got; Please run the following ( or something else&amp;nbsp; ) to verify how many rows you would be obtaining in the output; The&lt;STRONG&gt; Rows_in_output&lt;/STRONG&gt; will represent how many rows you can expect.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select count(*) as Rows_in_output from
(select distinct sqfmthyr, tract2010 from sqfmonthyear );
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please do post the result.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 01:05:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/746382#M234134</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-06-08T01:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating data from individual to census tract within date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/751826#M236730</link>
      <description>This worked perfectly!&lt;BR /&gt;Thanks!!!!</description>
      <pubDate>Fri, 02 Jul 2021 21:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-from-individual-to-census-tract-within-date/m-p/751826#M236730</guid>
      <dc:creator>casmcfarland</dc:creator>
      <dc:date>2021-07-02T21:13:17Z</dc:date>
    </item>
  </channel>
</rss>

