<?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: How do I calculate a new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-a-new-variable/m-p/500981#M133502</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226541"&gt;@JUMMY&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a data that looks like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;XX&lt;/P&gt;
&lt;P&gt;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The X variable are values rounded UP to the nearest 5.&amp;nbsp; And the XX variable indicate the number of years smoked as of January 1, 1982. How do I format these variables to indicate the descriptions I gave above? &lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's really hard to tell since your XX is all zeros, you have to give us meaningful example data for us to be able to help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With regards to X, rounding up to the next unit of 5 can be done like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x = round(x+2.49,5);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Because I want to calculate a new variable using X divided by 20 and then multiply by XX. How do I do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_variable = (x/20)*xx;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 02 Oct 2018 22:14:46 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-10-02T22:14:46Z</dc:date>
    <item>
      <title>How do I calculate a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-a-new-variable/m-p/500979#M133500</link>
      <description>&lt;P&gt;I have a data that looks like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;XX&lt;/P&gt;&lt;P&gt;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The X variable are values rounded UP to the nearest 5.&amp;nbsp; And the XX variable indicate the number of years smoked as of January 1, 1982. How do I format these variables to indicate the descriptions I gave above? Because I want to calculate a new variable using X divided by 20 and then multiply by XX. How do I do this?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 22:09:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-a-new-variable/m-p/500979#M133500</guid>
      <dc:creator>JUMMY</dc:creator>
      <dc:date>2018-10-02T22:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-a-new-variable/m-p/500981#M133502</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226541"&gt;@JUMMY&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a data that looks like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;XX&lt;/P&gt;
&lt;P&gt;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The X variable are values rounded UP to the nearest 5.&amp;nbsp; And the XX variable indicate the number of years smoked as of January 1, 1982. How do I format these variables to indicate the descriptions I gave above? &lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's really hard to tell since your XX is all zeros, you have to give us meaningful example data for us to be able to help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With regards to X, rounding up to the next unit of 5 can be done like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x = round(x+2.49,5);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Because I want to calculate a new variable using X divided by 20 and then multiply by XX. How do I do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_variable = (x/20)*xx;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Oct 2018 22:14:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-a-new-variable/m-p/500981#M133502</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-10-02T22:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-a-new-variable/m-p/500982#M133503</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226541"&gt;@JUMMY&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a data that looks like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;XX&lt;/P&gt;
&lt;P&gt;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The X variable are values rounded UP to the nearest 5.&amp;nbsp; And the XX variable indicate the number of years smoked as of January 1, 1982. How do I format these variables to indicate the descriptions I gave above? Because I want to calculate a new variable using X divided by 20 and then multiply by XX. How do I do this?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you know how to manually calculate the result you want you should show us what that result is for some of the values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have concerns about what you might mean by "&amp;nbsp;X variable are values rounded UP to the nearest 5". Since you don't show any values of 5 then your description of x seems incomplete.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The basic code would look something like:&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; newvalue = (x/20) * xx.&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;where have is a data set containing your x and xx variables.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 22:15:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-a-new-variable/m-p/500982#M133503</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-02T22:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-a-new-variable/m-p/500984#M133505</link>
      <description>&lt;P&gt;Why x+2.49? Why add 2.49?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 22:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-a-new-variable/m-p/500984#M133505</guid>
      <dc:creator>JUMMY</dc:creator>
      <dc:date>2018-10-02T22:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-a-new-variable/m-p/500985#M133506</link>
      <description>&lt;P&gt;Hint: try it. What happens if x=0, what do you get? What happens if x=0.1? What do you get?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 22:24:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-a-new-variable/m-p/500985#M133506</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-10-02T22:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-a-new-variable/m-p/500987#M133508</link>
      <description>&lt;P&gt;When X=0, I got 0 when I tried it. Unfortunately there is no x=0.1 in the data. Its all 0s and 1s. Thats why I needed help in converting the variables. Maybe some values are hidden. I am new to SAS.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 22:33:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-a-new-variable/m-p/500987#M133508</guid>
      <dc:creator>JUMMY</dc:creator>
      <dc:date>2018-10-02T22:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-a-new-variable/m-p/501012#M133526</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226541"&gt;@JUMMY&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;When X=0, I got 0 when I tried it. Unfortunately there is no x=0.1 in the data. Its all 0s and 1s. Thats why I needed help in converting the variables. Maybe some values are hidden. I am new to SAS.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The purpose is to think about what happens. There isn't a function that allows you to always round 'up' so to accomplish that you can add a factor that will cause it to round correctly all the time. A 'normal' round would round 0.1 to 0, when you want it rounded up to 5.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;How do I format these variables to indicate the descriptions I gave above?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;What do you mean by format? SAS has&amp;nbsp;format but I suspect that's not what you're looking for here.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;Because I want to calculate a new variable using X divided by 20 and then multiply by XX. How do I do this?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;You can calculate a new&amp;nbsp;variable in a data step or PROC SQL, but it's pretty easy to do this in a single line. Again, not&amp;nbsp;sure how this relates to your original post. I would suggest you post better example data and show what you&amp;nbsp;want as output if you need more specific help. Additionally, the first programming course in SAS is free (search free e course SAS ) and you'll find the latest links.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NewVar = (X / 20) * XX;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Oct 2018 02:00:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-a-new-variable/m-p/501012#M133526</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-03T02:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-a-new-variable/m-p/501073#M133553</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226541"&gt;@JUMMY&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;When X=0, I got 0 when I tried it. Unfortunately there is no x=0.1 in the data. Its all 0s and 1s. Thats why I needed help in converting the variables. Maybe some values are hidden. I am new to SAS.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You could, instead of expecting the value to be in your data, actually think about what happens if X is 0.1. It's not a hard formula to think through.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, you could create phony data and see what happens is X is 0.1.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 10:49:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-a-new-variable/m-p/501073#M133553</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-10-03T10:49:56Z</dc:date>
    </item>
  </channel>
</rss>

