<?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: Creating new variables using counts and multipliers in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Creating-new-variables-using-counts-and-multipliers/m-p/780152#M31617</link>
    <description>&lt;P&gt;Sorry for the confusion.&lt;/P&gt;&lt;P&gt;I put the PROC FREQ lines there to indicate how I generated the first 'have' dataset for a single concert.&lt;/P&gt;&lt;P&gt;The PROC SUMMARY works well to calculate the total number of tickets from a single concert. Is there a way to combine all three total calculations (organized by concert) into a new dataset without running three PROC SUMMARY commands and then manually entering results into a new dataset?&lt;/P&gt;</description>
    <pubDate>Sun, 14 Nov 2021 19:56:05 GMT</pubDate>
    <dc:creator>EmilyAV</dc:creator>
    <dc:date>2021-11-14T19:56:05Z</dc:date>
    <item>
      <title>Creating new variables using counts and multipliers</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-new-variables-using-counts-and-multipliers/m-p/780142#M31613</link>
      <description>&lt;P&gt;I have a dataset (generated from proc freq) organized as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input tickets $ count;&lt;BR /&gt;datalines;&lt;BR /&gt;0 600&lt;BR /&gt;1 278&lt;BR /&gt;2 992&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Two questions:&lt;/P&gt;&lt;P&gt;1) How can I calculate the total number of tickets sold from these output counts?&lt;/P&gt;&lt;P&gt;Total should = 0*600 + 1*278 + 2*992&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;length total 8.;&lt;BR /&gt;set have;&lt;BR /&gt;total = tickets*count;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;My current code generates a total by row but not a total for the whole dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Is there a way to do these steps iteratively, for multiple different variables (e.g. different concerts) in the same dataset so that the final dataset generated is organized like this?&lt;/P&gt;&lt;P&gt;concert1 total1&lt;/P&gt;&lt;P&gt;concert2 total2&lt;/P&gt;&lt;P&gt;concert3 total3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Nov 2021 15:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-new-variables-using-counts-and-multipliers/m-p/780142#M31613</guid>
      <dc:creator>EmilyAV</dc:creator>
      <dc:date>2021-11-14T15:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variables using counts and multipliers</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-new-variables-using-counts-and-multipliers/m-p/780143#M31614</link>
      <description>&lt;P&gt;This is a weighted sum. PROC SUMMARY makes this easy&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input tickets count; /* Note: you had tickets as a character variable, I have changed it in this code to numeric */
datalines;
0 600
1 278
2 992
;
proc summary data=have;
    var count;   
    weight tickets;
    output out=total sum=total;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Regarding your question 2, it would certainly help for you to show an example of this data set with "multiple different variables (e.g. different concerts)". I suspect you mean you have another variable (which I will call concert_name) and the same variables count and tickets. In this case, adding &lt;FONT face="courier new,courier"&gt;class concert_name;&lt;/FONT&gt; into the PROC SUMMARY code will get you the results you want. But really, show us the data set that has multiple concerts.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Nov 2021 16:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-new-variables-using-counts-and-multipliers/m-p/780143#M31614</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-14T16:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variables using counts and multipliers</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-new-variables-using-counts-and-multipliers/m-p/780144#M31615</link>
      <description>&lt;P&gt;Thank you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The original dataset looks like this, with one observation per customer (only the first 5 customers displayed), and the number of tickets they purchased for each of 3 different concerts:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data original;
	input id concert1 concert2 concert3;
	datalines;
	1 1 1 2
	2 1 2 2
	3 2 0 0
	4 0 2 0
	5 1 2 0
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;dataset have below was generated using proc freq from the first concert (have 1)...&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc freq data=original;
	table concert1 / nocum nopercent out=have1;
	table concert2 / nocum nopercent out=have2;
	table concert3 / nocum nopercent out=have3;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Nov 2021 16:38:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-new-variables-using-counts-and-multipliers/m-p/780144#M31615</guid>
      <dc:creator>EmilyAV</dc:creator>
      <dc:date>2021-11-14T16:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variables using counts and multipliers</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-new-variables-using-counts-and-multipliers/m-p/780149#M31616</link>
      <description>&lt;P&gt;This is very different data than your original post, where you wanted to multiply the number of tickets times a variable named COUNT, and then sum everything up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, it seems like you do not want to multiply the number of tickets times a count and sum everything up.&amp;nbsp;Now it seems like you want to just get a frequency (PROC FREQ) for each variable named CONCERT1 CONCERT2 CONCERT3 ... am I understanding that properly? Please state clearly: What is the desired output from this new data?&lt;/P&gt;</description>
      <pubDate>Sun, 14 Nov 2021 18:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-new-variables-using-counts-and-multipliers/m-p/780149#M31616</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-14T18:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variables using counts and multipliers</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-new-variables-using-counts-and-multipliers/m-p/780152#M31617</link>
      <description>&lt;P&gt;Sorry for the confusion.&lt;/P&gt;&lt;P&gt;I put the PROC FREQ lines there to indicate how I generated the first 'have' dataset for a single concert.&lt;/P&gt;&lt;P&gt;The PROC SUMMARY works well to calculate the total number of tickets from a single concert. Is there a way to combine all three total calculations (organized by concert) into a new dataset without running three PROC SUMMARY commands and then manually entering results into a new dataset?&lt;/P&gt;</description>
      <pubDate>Sun, 14 Nov 2021 19:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-new-variables-using-counts-and-multipliers/m-p/780152#M31617</guid>
      <dc:creator>EmilyAV</dc:creator>
      <dc:date>2021-11-14T19:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variables using counts and multipliers</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-new-variables-using-counts-and-multipliers/m-p/780153#M31618</link>
      <description>&lt;P&gt;Why use PROC FREQ at all, if you want sums?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data original;
	input id concert1 concert2 concert3;
	datalines;
	1 1 1 2
	2 1 2 2
	3 2 0 0
	4 0 2 0
	5 1 2 0
;
run;
proc summary data=original;
    var concert1-concert3;
    output out=_sums_ sum=/autoname;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Nov 2021 20:18:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-new-variables-using-counts-and-multipliers/m-p/780153#M31618</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-14T20:18:15Z</dc:date>
    </item>
  </channel>
</rss>

