<?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: Given dataset1, how to create dataset2 containing  the sums similar dataset1 rows? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Given-dataset1-how-to-create-dataset2-containing-the-sums-of/m-p/831351#M328497</link>
    <description>&lt;P&gt;One way to create data set.&lt;/P&gt;
&lt;PRE&gt;proc summary data=dataset1 nway;
   class user;
   var acres;
   output out=dataset2 (drop=_:) sum=total_acres;
run;&lt;/PRE&gt;</description>
    <pubDate>Thu, 01 Sep 2022 01:02:21 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-09-01T01:02:21Z</dc:date>
    <item>
      <title>Given dataset1, how to create dataset2 containing  the sums of similar dataset1 rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Given-dataset1-how-to-create-dataset2-containing-the-sums-of/m-p/831350#M328496</link>
      <description>&lt;P&gt;&lt;FONT face="courier new,courier"&gt;I'm new to SAS, am starting to watch the beginner tutorials, and would appreciate advice on implementing this problem:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Given existing dataset1:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; USER&amp;nbsp; &amp;nbsp;ACRES&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; John&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; John&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; Tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; Tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; Tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; (and more)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;I'd like SAS to create dataset2, containing one record per USER containing total acres:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; USER&amp;nbsp; &amp;nbsp; TOTAL_ACRES&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; John&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; Tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; (and more)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;No report, just a new dataset (dataset2).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Advice would be appreciated.&amp;nbsp; Or perhaps there's already a tutorial for this?&amp;nbsp;&amp;nbsp;&lt;/FONT&gt; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 01:44:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Given-dataset1-how-to-create-dataset2-containing-the-sums-of/m-p/831350#M328496</guid>
      <dc:creator>sasmhe1</dc:creator>
      <dc:date>2022-09-01T01:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: Given dataset1, how to create dataset2 containing  the sums similar dataset1 rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Given-dataset1-how-to-create-dataset2-containing-the-sums-of/m-p/831351#M328497</link>
      <description>&lt;P&gt;One way to create data set.&lt;/P&gt;
&lt;PRE&gt;proc summary data=dataset1 nway;
   class user;
   var acres;
   output out=dataset2 (drop=_:) sum=total_acres;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Sep 2022 01:02:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Given-dataset1-how-to-create-dataset2-containing-the-sums-of/m-p/831351#M328497</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-01T01:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: Given dataset1, how to create dataset2 containing  the sums similar dataset1 rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Given-dataset1-how-to-create-dataset2-containing-the-sums-of/m-p/831353#M328499</link>
      <description>&lt;P&gt;Thank you, ballardw.&lt;/P&gt;&lt;P&gt;I tried the code in SAS Studio, but got:&amp;nbsp;Libref .. is not assigned.&lt;/P&gt;&lt;P&gt;I'll continue with the beginner tutorials to understand this message, and if I don't succeed, I'll return with another question!&lt;/P&gt;&lt;P&gt;Thank you again.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 01:29:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Given-dataset1-how-to-create-dataset2-containing-the-sums-of/m-p/831353#M328499</guid>
      <dc:creator>sasmhe1</dc:creator>
      <dc:date>2022-09-01T01:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: Given dataset1, how to create dataset2 containing  the sums similar dataset1 rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Given-dataset1-how-to-create-dataset2-containing-the-sums-of/m-p/831359#M328505</link>
      <description>&lt;P&gt;Show the entire log of what you submitted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Libref means &lt;STRONG&gt;you&lt;/STRONG&gt; attempted to use a library that is not defined in your current session. There is no we would know anything about what libraries you have. Basically you would have had to use something like data= some.dataset1&amp;nbsp; The . tells SAS that SOME is supposed to be the name of a library, physical storage location for the dataset named Dataset1.&lt;/P&gt;
&lt;P&gt;Normally a LIBNAME statement is provided to create a library reference (libref).&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 03:37:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Given-dataset1-how-to-create-dataset2-containing-the-sums-of/m-p/831359#M328505</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-01T03:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: Given dataset1, how to create dataset2 containing  the sums of similar dataset1 rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Given-dataset1-how-to-create-dataset2-containing-the-sums-of/m-p/831370#M328510</link>
      <description>&lt;P&gt;While using PROC SUMMARY is the recommended way, here two other ways using SQL or a SORT/DATA step combination:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create dataset2 as
  select
    user,
    sum(acres) as total_acres
  from dataset1
  group by user
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=dataset1;
by user;
run;

data dataset2;
set dataset1;
by user;
if first.user
then total_acres = acres;
else total_acres + acres;
if last.user; /* subsetting IF, causes only one output per group */
keep user total_acres;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The statement in the ELSE branch is a &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lestmtsref/n1dfiqj146yi2cn1maeju9wo7ijs.htm" target="_blank" rel="noopener"&gt;SUM Statement&lt;/A&gt;&amp;nbsp; and implies an automatic RETAIN of the summed variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DATA step method is often needed when you need to do accumulations of values which cannot be handled with the summary functions of SQL or the statistics available in SUMMARY. Think concatenation of strings or determining presence of certain "vertical" value combinations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DATA step can also be done with a DO UNTIL loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataset2;
do until (last.user);
  set dataset1;
  by user;
  if first.user
  then total_acres = acres;
  else total_acres + acres;
end;
keep user total_acres;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Sep 2022 07:59:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Given-dataset1-how-to-create-dataset2-containing-the-sums-of/m-p/831370#M328510</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-01T07:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: Given dataset1, how to create dataset2 containing  the sums similar dataset1 rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Given-dataset1-how-to-create-dataset2-containing-the-sums-of/m-p/831452#M328553</link>
      <description>&lt;P&gt;Hi ballardw,&lt;/P&gt;&lt;P&gt;Your method worked (I got around the libref problem).&lt;/P&gt;&lt;P&gt;Now I need to understand why it worked (may take a while).&lt;/P&gt;&lt;P&gt;Thank you again.&lt;/P&gt;&lt;P&gt;P.S.&amp;nbsp; Thanks also to the other responses, as I'd like to learn those methods also.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 18:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Given-dataset1-how-to-create-dataset2-containing-the-sums-of/m-p/831452#M328553</guid>
      <dc:creator>sasmhe1</dc:creator>
      <dc:date>2022-09-01T18:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: Given dataset1, how to create dataset2 containing  the sums similar dataset1 rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Given-dataset1-how-to-create-dataset2-containing-the-sums-of/m-p/831456#M328557</link>
      <description>&lt;P&gt;I highly recommend learning and understanding PROC MEANS. Pick one proc, learn it well, then learn other ways. PROC MEANS is incredibly versatile and can do many different summary statistics so it's a great place to start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a decent quick walkthrough of the features&lt;/P&gt;
&lt;P&gt;&lt;A href="https://sascrunch.com/proc-means/" target="_blank"&gt;https://sascrunch.com/proc-means/&lt;/A&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 18:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Given-dataset1-how-to-create-dataset2-containing-the-sums-of/m-p/831456#M328557</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-01T18:56:43Z</dc:date>
    </item>
  </channel>
</rss>

