<?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: Exporting a table of aggregate outcomes using sas proc sql in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Exporting-a-table-of-aggregate-outcomes-using-sas-proc-sql/m-p/677043#M32478</link>
    <description>&lt;P&gt;So it seems you already have the number of new acquisitions per day, and we do not need to build the difference to the previous day.&lt;/P&gt;
&lt;P&gt;Note that "wide" datasets are much harder to process than the "long" dataset you already have now.&lt;/P&gt;
&lt;P&gt;Is this for reporting purposes?&lt;/P&gt;</description>
    <pubDate>Sun, 16 Aug 2020 08:15:41 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-08-16T08:15:41Z</dc:date>
    <item>
      <title>Exporting a table of aggregate outcomes using sas proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Exporting-a-table-of-aggregate-outcomes-using-sas-proc-sql/m-p/677028#M32473</link>
      <description>&lt;P&gt;I have a dataset that contains millions of records about the details of loans in China. I want to do a city-level panel data analysis where I need the daily increment of the number of loans in a city. My basic idea is to count the observations with the specified value of city names and dates. Hopefully, I want to generate a table that contains all the counts at one time where the city list is the first column, and the date list is the first row. I design some very fundamental codes like this:&lt;/P&gt;&lt;PRE&gt;proc sql;

select count(*) as N_obs
from rrd_come.combo_comprehensive_29
where borrower_officelocation in 'beijing' and project_opentime_cn=20200131;

quit;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;But it can only output the daily increment of one city at one data, which is far below my requirements.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 257px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/48277iCA2B720234326DB4/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;I want to generate a table of like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="applemonster_0-1597556568217.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/48278i554811246195E822/image-size/medium?v=v2&amp;amp;px=400" role="button" title="applemonster_0-1597556568217.png" alt="applemonster_0-1597556568217.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So could any generous friends help me out?&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 05:47:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Exporting-a-table-of-aggregate-outcomes-using-sas-proc-sql/m-p/677028#M32473</guid>
      <dc:creator>applemonster</dc:creator>
      <dc:date>2020-08-16T05:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting a table of aggregate outcomes using sas proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Exporting-a-table-of-aggregate-outcomes-using-sas-proc-sql/m-p/677030#M32474</link>
      <description>&lt;P&gt;First, convert these mostly unusable numbers to SAS date values, which will aid greatly in further processing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, create a table with number of loans per city and date by using GROUP BY:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    borrower_officelocation,
    project_opentime_cn,
    count(*) as N_obs
  from rrd_come.combo_comprehensive_29
  group by borrower_officelocation, project_opentime_cn
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can calculate the difference between dates in a data step with LAG().&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 06:31:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Exporting-a-table-of-aggregate-outcomes-using-sas-proc-sql/m-p/677030#M32474</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-16T06:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting a table of aggregate outcomes using sas proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Exporting-a-table-of-aggregate-outcomes-using-sas-proc-sql/m-p/677040#M32476</link>
      <description>&lt;P&gt;It is a very inspiring way to figure it out! Thank you so much.&amp;nbsp;&lt;/P&gt;&lt;P&gt;After following your idea, I got a dataset with three columns: borrower_officelocation, project_opentime_cn, and N_obs;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="applemonster_0-1597564138605.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/48279i3AEE440FB5EF3BC6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="applemonster_0-1597564138605.png" alt="applemonster_0-1597564138605.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;(Please igonre the Chinese characters...)&lt;/P&gt;&lt;P&gt;But could you please shed more light on how to transfer such a dataset into a format I desire like below one using data step and lag() function?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="applemonster_1-1597564325838.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/48280i06AB6DF78AB05C44/image-size/medium?v=v2&amp;amp;px=400" role="button" title="applemonster_1-1597564325838.png" alt="applemonster_1-1597564325838.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 07:52:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Exporting-a-table-of-aggregate-outcomes-using-sas-proc-sql/m-p/677040#M32476</guid>
      <dc:creator>applemonster</dc:creator>
      <dc:date>2020-08-16T07:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting a table of aggregate outcomes using sas proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Exporting-a-table-of-aggregate-outcomes-using-sas-proc-sql/m-p/677043#M32478</link>
      <description>&lt;P&gt;So it seems you already have the number of new acquisitions per day, and we do not need to build the difference to the previous day.&lt;/P&gt;
&lt;P&gt;Note that "wide" datasets are much harder to process than the "long" dataset you already have now.&lt;/P&gt;
&lt;P&gt;Is this for reporting purposes?&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 08:15:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Exporting-a-table-of-aggregate-outcomes-using-sas-proc-sql/m-p/677043#M32478</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-16T08:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting a table of aggregate outcomes using sas proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Exporting-a-table-of-aggregate-outcomes-using-sas-proc-sql/m-p/677044#M32479</link>
      <description>I have known your meaning by using lag() function. I need to say that N_obs is already an incremental value instead of accumulative value, so it is unnecessary to do difference calculation again. I feel the next step is a brand-new issue and I'd better post another question. Thanks a lot!</description>
      <pubDate>Sun, 16 Aug 2020 08:15:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Exporting-a-table-of-aggregate-outcomes-using-sas-proc-sql/m-p/677044#M32479</guid>
      <dc:creator>applemonster</dc:creator>
      <dc:date>2020-08-16T08:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting a table of aggregate outcomes using sas proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Exporting-a-table-of-aggregate-outcomes-using-sas-proc-sql/m-p/677047#M32480</link>
      <description>&lt;P&gt;What you are after is a transpose, but this is usually only good for reporting purposes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you trying to export this for human consumption (e.g. to Excel)?&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 08:23:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Exporting-a-table-of-aggregate-outcomes-using-sas-proc-sql/m-p/677047#M32480</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-16T08:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting a table of aggregate outcomes using sas proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Exporting-a-table-of-aggregate-outcomes-using-sas-proc-sql/m-p/677049#M32485</link>
      <description>&lt;P&gt;It's not used for report purpose. I want to do panel data analysis of the impact of COVID19 on the lending and borrowing activities in China. Panel data analysis typically studies multiple areas over multiple periods. I want to treat loan number, average loan size and other similar variables of a city as explained variables, and handle daily new COVID19 cases and other control variables as explaining variables. So I think it is instinctively and visually better to adopt such a dataset format. But obviously, I am not a data scientist yet, so I hope that you can give me some constructive suggestions.&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 10:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Exporting-a-table-of-aggregate-outcomes-using-sas-proc-sql/m-p/677049#M32485</guid>
      <dc:creator>applemonster</dc:creator>
      <dc:date>2020-08-16T10:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting a table of aggregate outcomes using sas proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Exporting-a-table-of-aggregate-outcomes-using-sas-proc-sql/m-p/677053#M32486</link>
      <description>&lt;P&gt;Then you can run PROC TRANSPOSE on the "want" dataset from my previous post:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose
  data=want
  out=want_wide
  prefix=date_ /* you can't start a variable name with a number */
;
by borrower_officelocation;
var n_obs;
id project_opentime_cn;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 16 Aug 2020 11:17:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Exporting-a-table-of-aggregate-outcomes-using-sas-proc-sql/m-p/677053#M32486</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-16T11:17:01Z</dc:date>
    </item>
  </channel>
</rss>

