<?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 Trim data set in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Trim-data-set/m-p/230484#M2402</link>
    <description>&lt;P&gt;Goodday to you,&lt;/P&gt;&lt;P&gt;I am trying to trim the data set which is sorted in ascending order. I have no idea how to trim the data set from start and end for k% of data. Basically&amp;nbsp;most of the post I could found&amp;nbsp;is how to&amp;nbsp;perform trimmed mean, but what I want is just trim the data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;XN = DAT[POS1:ENDPOS];&lt;BR /&gt;CALL SORT(XN);&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am very new to SAS IML, hope someone could help me out.&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Sun, 18 Oct 2015 15:12:31 GMT</pubDate>
    <dc:creator>vince_tsp</dc:creator>
    <dc:date>2015-10-18T15:12:31Z</dc:date>
    <item>
      <title>Trim data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Trim-data-set/m-p/230484#M2402</link>
      <description>&lt;P&gt;Goodday to you,&lt;/P&gt;&lt;P&gt;I am trying to trim the data set which is sorted in ascending order. I have no idea how to trim the data set from start and end for k% of data. Basically&amp;nbsp;most of the post I could found&amp;nbsp;is how to&amp;nbsp;perform trimmed mean, but what I want is just trim the data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;XN = DAT[POS1:ENDPOS];&lt;BR /&gt;CALL SORT(XN);&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am very new to SAS IML, hope someone could help me out.&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Sun, 18 Oct 2015 15:12:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Trim-data-set/m-p/230484#M2402</guid>
      <dc:creator>vince_tsp</dc:creator>
      <dc:date>2015-10-18T15:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: Trim data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Trim-data-set/m-p/230534#M2403</link>
      <description>&lt;P&gt;Gday!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not sure if/why you need IML. Regular datastep code would be something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let percentage = 20;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data trimmed;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set base nobs=size;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if (size * &amp;amp;percentage / 200) &amp;lt;= _N_ &amp;lt;= size - (size * &amp;amp;percentage / 200) then output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Eric&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2015 07:51:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Trim-data-set/m-p/230534#M2403</guid>
      <dc:creator>EH</dc:creator>
      <dc:date>2015-10-19T07:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: Trim data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Trim-data-set/m-p/230542#M2405</link>
      <description>&lt;P&gt;Trimming is the act of truncating the upper and lower tails of an empirical UNIVARIATE distribution, so&amp;nbsp;we don't usually talk about trimming a data set, we talk about trimming a variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To trim a variable, look at p. 2-3 of &lt;A href="http://support.sas.com/resources/papers/proceedings10/329-2010.pdf" target="_self"&gt;my 2010 SAS Global Forum paper&lt;/A&gt;, which has an algorithm for computing the&amp;nbsp;trimmed mean and variance of every column in a matrix.&amp;nbsp; You can modify it to extract&amp;nbsp;the "middle" observations:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
/* assume v is a column vector. Return the sorted 
   elements that result from trimming the largest and smallest
   proportion of values. The 'prop' parameter is 0 &amp;lt; prop &amp;lt; 1. */
start TrimVec(v, prop);
   n = nrow(v);      /* num rows (assume no missing values) */
   d = ceil(prop*n); /* number of observations to trim */
   z = v;            /* copy it */
   call sort(z,1);   /* sort it */
   w = z[d+1:n-d, ]; /* trim d largest and d smallest values */
   return (w);
finish;

use sashelp.cars;
read all var "mpg_city" into x;
close;
trimX = TrimVec(x, 0.12);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The key is the statement&lt;/P&gt;
&lt;P&gt;w = z[ d+1:n-d, ];&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;expression &amp;nbsp;d+1:n-d uses the index operator (:) to represent the observations to keep.&amp;nbsp; You can use the same syntax to extract those rows from an entire matrix:&lt;/P&gt;
&lt;P&gt;smallerMatrix = bigMatrix[ d+1:n-d, ];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See the article&lt;A href="http://blogs.sas.com/content/iml/2011/01/10/creating-vectors-that-contain-evenly-spaced-values.html" target="_self"&gt; "Creating vectors that contain evenly spaced values" &lt;/A&gt;for a description of the index operator (:) .&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2015 10:25:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Trim-data-set/m-p/230542#M2405</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2015-10-19T10:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: Trim data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Trim-data-set/m-p/230673#M2406</link>
      <description>Thanks for your try to help me. Really appreciated that.</description>
      <pubDate>Tue, 20 Oct 2015 07:26:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Trim-data-set/m-p/230673#M2406</guid>
      <dc:creator>vince_tsp</dc:creator>
      <dc:date>2015-10-20T07:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: Trim data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Trim-data-set/m-p/230674#M2407</link>
      <description>Thanks Rick, finally I got my solution after 1 weeks try and errors.</description>
      <pubDate>Tue, 20 Oct 2015 07:28:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Trim-data-set/m-p/230674#M2407</guid>
      <dc:creator>vince_tsp</dc:creator>
      <dc:date>2015-10-20T07:28:11Z</dc:date>
    </item>
  </channel>
</rss>

