<?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 to extract positive and negative numbers for corresponding calculation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-positive-and-negative-numbers-for-corresponding/m-p/302278#M64105</link>
    <description>&lt;P&gt;Use an if statement and dim() function:&lt;/P&gt;
&lt;P&gt;if dim(pos) &amp;gt; 2 then res1=std(of pos{*});&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No need to fill in . as that is default.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Oct 2016 08:10:14 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-10-04T08:10:14Z</dc:date>
    <item>
      <title>How to extract positive and negative numbers for corresponding calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-positive-and-negative-numbers-for-corresponding/m-p/301762#M63916</link>
      <description>&lt;P&gt;Dear&amp;nbsp; Expert&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know to extract positive and negative numbers from the columns separately and use it to calculate the standard deviation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a table&lt;/P&gt;
&lt;P&gt;Asset rd&amp;nbsp;&amp;nbsp;&amp;nbsp; rd1&amp;nbsp;&amp;nbsp; rd2 rd3&lt;/P&gt;
&lt;P&gt;APPL 0.2 -0.1 -1.2&amp;nbsp;&amp;nbsp; 0.6&lt;/P&gt;
&lt;P&gt;IBM&amp;nbsp;&amp;nbsp; 4.1&amp;nbsp; -2.3 -1.1&amp;nbsp; 4.2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wish to calculate standard deviation for positve and negative values separately ie for APPL&lt;/P&gt;
&lt;P&gt;spread_pos = std(0.2, 0.6)&lt;/P&gt;
&lt;P&gt;spread_neg = std(-0.1, -1.2)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;spread_ratio = spread_pos / spread_neg&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hence the final table will look like&lt;/P&gt;
&lt;P&gt;Asset rd&amp;nbsp;&amp;nbsp;&amp;nbsp; rd1&amp;nbsp;&amp;nbsp; rd2&amp;nbsp; &amp;nbsp;rd3&amp;nbsp;&amp;nbsp; spread_ratio&lt;/P&gt;
&lt;P&gt;APPL 0.2 -0.1&amp;nbsp; -1.2&amp;nbsp;&amp;nbsp; 0.6&amp;nbsp;&amp;nbsp; 0.363&lt;/P&gt;
&lt;P&gt;IBM&amp;nbsp;&amp;nbsp; 4.1&amp;nbsp; -2.3&amp;nbsp; -1.1&amp;nbsp;&amp;nbsp; 4.2&amp;nbsp;&amp;nbsp; 0.083&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it possible to do within a data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data XXX;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set tableA&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if rd &amp;gt; 0 or rd1 &amp;gt; 0 or rd2 &amp;gt; 0 or rd3 &amp;gt;0 then do&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; spread_pos = std(rd, rd1, rd2, rd3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;if rd&amp;nbsp;&amp;lt; 0 or rd1&amp;nbsp;&amp;lt; 0 or rd2&amp;nbsp;&amp;lt; 0 or rd3 &amp;lt;0 then do&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; spread_neg = std(rd, rd1, rd2, rd3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; spread_ratio = spread_pos / spread_neg;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by asset;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code above has problem. It will always calculate the standard deviation for all rdX.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks&lt;/P&gt;
&lt;P&gt;Leo&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2016 14:51:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-positive-and-negative-numbers-for-corresponding/m-p/301762#M63916</guid>
      <dc:creator>CheerfulChu</dc:creator>
      <dc:date>2016-09-30T14:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract positive and negative numbers for corresponding calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-positive-and-negative-numbers-for-corresponding/m-p/301772#M63919</link>
      <description>&lt;P&gt;You could use three arrays:&lt;/P&gt;
&lt;P&gt;array rd...;&lt;/P&gt;
&lt;P&gt;array pos...;&lt;/P&gt;
&lt;P&gt;array neg...;&lt;/P&gt;
&lt;P&gt;do&amp;nbsp;i=1 to dim(rd);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if rd{i} &amp;gt; 0 then pos{i}=rd{i};&lt;/P&gt;
&lt;P&gt;&amp;nbsp; else neg{i}=rd{i};&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;res1=std(of pos{*});&lt;/P&gt;
&lt;P&gt;res2=std(of neg{*});&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2016 15:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-positive-and-negative-numbers-for-corresponding/m-p/301772#M63919</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-09-30T15:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract positive and negative numbers for corresponding calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-positive-and-negative-numbers-for-corresponding/m-p/302182#M64068</link>
      <description>&lt;P&gt;Hi Expert,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code works great.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, i receive one error which is when there are no elements or only one element when calculating:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;nbsp;res1=std(of pos{*});&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it possible to assign res1 = . when the number of elements in pos array is less than 2? I cant use dim(pos) because I have defined:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;array pos {12} pos1 - pos12;&lt;/PRE&gt;
&lt;P&gt;Many thanks&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 22:06:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-positive-and-negative-numbers-for-corresponding/m-p/302182#M64068</guid>
      <dc:creator>CheerfulChu</dc:creator>
      <dc:date>2016-10-03T22:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract positive and negative numbers for corresponding calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-positive-and-negative-numbers-for-corresponding/m-p/302278#M64105</link>
      <description>&lt;P&gt;Use an if statement and dim() function:&lt;/P&gt;
&lt;P&gt;if dim(pos) &amp;gt; 2 then res1=std(of pos{*});&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No need to fill in . as that is default.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 08:10:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-positive-and-negative-numbers-for-corresponding/m-p/302278#M64105</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-10-04T08:10:14Z</dc:date>
    </item>
  </channel>
</rss>

