<?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 Calculation in Case When Statement in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617217#M19039</link>
    <description>&lt;P&gt;Good day All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A happy new year to you all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please assist me with my inquiry:&lt;/P&gt;&lt;P&gt;I want to firstly calculate a new instalment value but I want to create columns so that each account entry has 1 account number with different instalment values as columns. The only instalment value that changes is the 6 plan instalment with a formula of (instalment * 0.5572)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how the data looks:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;account number&lt;/TD&gt;&lt;TD&gt;plan&lt;/TD&gt;&lt;TD&gt;instalment&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;35&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;322&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;472&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;BR /&gt;The desired output:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;account number&lt;/TD&gt;&lt;TD&gt;plan1&lt;/TD&gt;&lt;TD&gt;plan6&lt;/TD&gt;&lt;TD&gt;plan12&lt;/TD&gt;&lt;TD&gt;calculated instalment1&lt;/TD&gt;&lt;TD&gt;calculated instalment6&lt;/TD&gt;&lt;TD&gt;calculated instalment12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;35&lt;/TD&gt;&lt;TD&gt;179&lt;/TD&gt;&lt;TD&gt;472&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Tue, 14 Jan 2020 15:33:11 GMT</pubDate>
    <dc:creator>MagD</dc:creator>
    <dc:date>2020-01-14T15:33:11Z</dc:date>
    <item>
      <title>Calculation in Case When Statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617217#M19039</link>
      <description>&lt;P&gt;Good day All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A happy new year to you all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please assist me with my inquiry:&lt;/P&gt;&lt;P&gt;I want to firstly calculate a new instalment value but I want to create columns so that each account entry has 1 account number with different instalment values as columns. The only instalment value that changes is the 6 plan instalment with a formula of (instalment * 0.5572)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how the data looks:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;account number&lt;/TD&gt;&lt;TD&gt;plan&lt;/TD&gt;&lt;TD&gt;instalment&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;35&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;322&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;472&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;BR /&gt;The desired output:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;account number&lt;/TD&gt;&lt;TD&gt;plan1&lt;/TD&gt;&lt;TD&gt;plan6&lt;/TD&gt;&lt;TD&gt;plan12&lt;/TD&gt;&lt;TD&gt;calculated instalment1&lt;/TD&gt;&lt;TD&gt;calculated instalment6&lt;/TD&gt;&lt;TD&gt;calculated instalment12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;35&lt;/TD&gt;&lt;TD&gt;179&lt;/TD&gt;&lt;TD&gt;472&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 14 Jan 2020 15:33:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617217#M19039</guid>
      <dc:creator>MagD</dc:creator>
      <dc:date>2020-01-14T15:33:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation in Case When Statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617224#M19040</link>
      <description>&lt;P&gt;This ought to work. You have asked about CASE WHEN, but that is not needed here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
    input account plan installment;
	cards;
123456789	1	35
123456789	6	322
123456789	12	472
;

proc transpose data=a out=b prefix=installment;
    var installment;
	id plan;
run;

data b;
    set b;
	installment6=installment6*0.5572;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 15:47:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617224#M19040</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-14T15:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation in Case When Statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617241#M19042</link>
      <description>&lt;P&gt;Hi Paige,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not too familiar with the solution that you provided below. I see in the first data step, there is no 'set' step. How do I go about incorporating your solution by setting a location for where the data originates from?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 16:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617241#M19042</guid>
      <dc:creator>MagD</dc:creator>
      <dc:date>2020-01-14T16:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation in Case When Statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617248#M19044</link>
      <description>You ignore the first data step, that's creating the raw data to work with and work from the second step. PROC TRANSPOSE restructures your data and the the last data step does the calculations you need.</description>
      <pubDate>Tue, 14 Jan 2020 16:45:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617248#M19044</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-14T16:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation in Case When Statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617250#M19045</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have over 30, 000 accounts that I need to use this solution for. Is there a way around this by setting the location of the raw data to be used?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 17:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617250#M19045</guid>
      <dc:creator>MagD</dc:creator>
      <dc:date>2020-01-14T17:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation in Case When Statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617254#M19046</link>
      <description>&lt;PRE&gt;*sort data so you have correct order for transpose;
proc sort data=have &lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;/*have is your input data set*/&lt;/FONT&gt;&lt;/STRONG&gt;
              out=a; &lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;/*creates a new copy of input data that is sorted called A*/&lt;/STRONG&gt;&lt;/FONT&gt;
&lt;FONT size="4" color="#FF0000"&gt;&lt;STRONG&gt;by accountNo; &lt;/STRONG&gt;&lt;/FONT&gt;
run;

*this step flips your data to a long structure;
proc transpose data=a  &lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;/*input data set is A*/&lt;/STRONG&gt;&lt;/FONT&gt;
                         out=b  &lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;/*output data set is B*/&lt;/STRONG&gt;&lt;/FONT&gt;
                         prefix=installment; &lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;/*Prefix for new variables*/&lt;/FONT&gt;&lt;/STRONG&gt;
  &lt;FONT size="4" color="#FF0000"&gt;&lt;STRONG&gt; by accountNo;&lt;/STRONG&gt;&lt;/FONT&gt;
    var installment;&lt;FONT color="#FF6600"&gt;&lt;STRONG&gt; /*vars to fill inner cells of table*/&lt;/STRONG&gt;&lt;/FONT&gt;
    id plan; &lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;/*variable to differentiate the column names in output table*/&lt;/FONT&gt;&lt;/STRONG&gt;
run;

*do calculations;
data want; &lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;/*want is your output dataset*/&lt;/STRONG&gt;&lt;/FONT&gt;
    set b; &lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;/*b is your input data set from previous step*/&lt;/FONT&gt;&lt;/STRONG&gt;
	installment6=installment6*0.5572; &lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;/*desired calculation*/&lt;/FONT&gt;&lt;/STRONG&gt;
run;&lt;/PRE&gt;
&lt;P&gt;This a commented version that should answer all your questions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please review this post to understand how PROC TRANSPOSE works.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Long to Wide:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/" target="_blank" rel="noopener"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;If you want to understand code, run it. Identify the input and output data sets and compare the two data sets to understand what's changed. Then look at the code and figure out what each line does. Then start changing it to fit your situation.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;EDIT: You hadn't mentioned multiple accounts and your example only had one account so the original solution provided would have worked for a single account. To incorporate multiple&amp;nbsp;accounts, you really should include that from the start btw, you need to add a BY statement. See the code in red above. Note that I don't know what your variable name actually is, so you'll need to correct for that.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 17:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617254#M19046</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-14T17:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation in Case When Statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617255#M19047</link>
      <description>&lt;P&gt;Thank you so much for all of your assistance!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 17:11:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617255#M19047</guid>
      <dc:creator>MagD</dc:creator>
      <dc:date>2020-01-14T17:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation in Case When Statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617256#M19048</link>
      <description>I added an edit to handle multiple accounts, please see previous post.</description>
      <pubDate>Tue, 14 Jan 2020 17:13:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617256#M19048</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-14T17:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation in Case When Statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617258#M19049</link>
      <description>&lt;P&gt;Thank you so much! It works. Thank you, thank you!!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 17:20:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculation-in-Case-When-Statement/m-p/617258#M19049</guid>
      <dc:creator>MagD</dc:creator>
      <dc:date>2020-01-14T17:20:31Z</dc:date>
    </item>
  </channel>
</rss>

