<?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 creating new variables in sas in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/creating-new-variables-in-sas/m-p/204516#M50963</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; background-color: #ffffff;"&gt;I want to create a new variable which is equal to the column sum of an existing variable monthly_sales.the code i am using is-&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; background-color: #ffffff;"&gt;&lt;CODE style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif;"&gt;data west;&lt;BR /&gt;input total;&lt;BR /&gt;set yash123;&lt;BR /&gt;&lt;BR /&gt;total=sum monthly_sales;&lt;BR /&gt;proc print data=west;&lt;BR /&gt;var total;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; background-color: #ffffff;"&gt;but it throws an error stating variable total not found.Please help&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Jul 2015 11:31:55 GMT</pubDate>
    <dc:creator>yashchawla</dc:creator>
    <dc:date>2015-07-16T11:31:55Z</dc:date>
    <item>
      <title>creating new variables in sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-new-variables-in-sas/m-p/204516#M50963</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; background-color: #ffffff;"&gt;I want to create a new variable which is equal to the column sum of an existing variable monthly_sales.the code i am using is-&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; background-color: #ffffff;"&gt;&lt;CODE style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif;"&gt;data west;&lt;BR /&gt;input total;&lt;BR /&gt;set yash123;&lt;BR /&gt;&lt;BR /&gt;total=sum monthly_sales;&lt;BR /&gt;proc print data=west;&lt;BR /&gt;var total;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; background-color: #ffffff;"&gt;but it throws an error stating variable total not found.Please help&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jul 2015 11:31:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-new-variables-in-sas/m-p/204516#M50963</guid>
      <dc:creator>yashchawla</dc:creator>
      <dc:date>2015-07-16T11:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variables in sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-new-variables-in-sas/m-p/204517#M50964</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You shouldn't need an input statement for your total variable you're creating.&amp;nbsp; You can use a format statement if you wish to define the variable a format ahead of time.&amp;nbsp; I think your issue is how you're trying to calculate the variable total.&amp;nbsp; Are you trying to sum all monthly_sales?&amp;nbsp; You should be getting a syntax error with your "total=sum monthly_sales;" statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you're looking to sum all monthly_sales observations to get a total amount, I would use a proc means statement or a proc sql with a group by statement.&amp;nbsp; Unless you're trying to cacluate total a different way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jul 2015 13:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-new-variables-in-sas/m-p/204517#M50964</guid>
      <dc:creator>dcruik</dc:creator>
      <dc:date>2015-07-16T13:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variables in sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-new-variables-in-sas/m-p/204518#M50965</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It would be easier if you gave an example of the data you have and want you want.&amp;nbsp; Here's a guess at your solution though:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input month monthly_sales;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 100&lt;/P&gt;&lt;P&gt;1 200&lt;/P&gt;&lt;P&gt;2 50&lt;/P&gt;&lt;P&gt;2 100&lt;/P&gt;&lt;P&gt;3 25&lt;/P&gt;&lt;P&gt;3 1&lt;/P&gt;&lt;P&gt;4 0&lt;/P&gt;&lt;P&gt;4 100&lt;/P&gt;&lt;P&gt;5 5000&lt;/P&gt;&lt;P&gt;5 100&lt;/P&gt;&lt;P&gt;6 100&lt;/P&gt;&lt;P&gt;6 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select *,sum(monthly_sales) as sum&lt;/P&gt;&lt;P&gt;from have&lt;/P&gt;&lt;P&gt;group by month;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jul 2015 13:17:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-new-variables-in-sas/m-p/204518#M50965</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-07-16T13:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variables in sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-new-variables-in-sas/m-p/204519#M50966</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi ,&lt;/P&gt;&lt;P&gt;Thanks for your reply. proc means and proc sql can be used to calculate sum.But then how can we relate that value to the new variable "total"?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jul 2015 14:25:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-new-variables-in-sas/m-p/204519#M50966</guid>
      <dc:creator>yashchawla</dc:creator>
      <dc:date>2015-07-16T14:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variables in sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-new-variables-in-sas/m-p/204520#M50967</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote" modifiedtitle="true"&gt;
&lt;P&gt;yashchawla wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;But then how can we relate that value to the new variable "total"?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What does that mean? A picture is worth a 1000 words, please post input and output data. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jul 2015 14:49:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-new-variables-in-sas/m-p/204520#M50967</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-07-16T14:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variables in sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-new-variables-in-sas/m-p/204521#M50968</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you mean how to create a variable named total that equals the total sum, then try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc means data=yash123 sum nway noprint;&lt;/P&gt;&lt;P&gt;var monthly_sales;&lt;/P&gt;&lt;P&gt;output out=west (drop=_TYPE_ _FREQ_)&lt;/P&gt;&lt;P&gt;sum=Total;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will give you a data set called west with a variable called Total that is equal to the sum of all monthly_sales.&amp;nbsp; If you want to see the sum of monthly_sales by Month, like Mark Johnson laid out, add a class statement to the means procedure with Month as your class:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc means data=yash123 sum nway noprint;&lt;/P&gt;&lt;P&gt;var monthly_sales;&lt;/P&gt;&lt;P&gt;class month;&lt;/P&gt;&lt;P&gt;output out=west (drop=_TYPE_ _FREQ_)&lt;/P&gt;&lt;P&gt;sum=Total;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jul 2015 15:14:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-new-variables-in-sas/m-p/204521#M50968</guid>
      <dc:creator>dcruik</dc:creator>
      <dc:date>2015-07-16T15:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variables in sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-new-variables-in-sas/m-p/204522#M50969</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My $0.02: In my opinion about the only reason to have a column sum (or other summary) is for a report as data like that is very dangerous to have in a data set used for analysis. So use of a reporting procedure and generate the report directly is preferable.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jul 2015 15:25:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-new-variables-in-sas/m-p/204522#M50969</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-07-16T15:25:17Z</dc:date>
    </item>
  </channel>
</rss>

