<?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 Create separate array for first observed unique number in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-separate-array-for-first-observed-unique-number/m-p/704642#M216030</link>
    <description>&lt;P&gt;I have multi dimensional array of numeric numbers.&amp;nbsp; I would like to create separate multi dimensional array that shows the first observed unique numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have1;&lt;BR /&gt;input a1_1-a1_4 b1_1-b1_4 c1_1-c1_4;&lt;BR /&gt;datalines;&lt;BR /&gt;2000 2001 2002 . 2001 2004 . . 2002 2004 2005 20006&lt;BR /&gt;2000 2002 2003 2004 2003 2004 . . 2002 2005 2006 .&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data want1;&lt;BR /&gt;input fa1_1-fa1_4 fb1_1-fb1_4 fc1_1-fc1_4;&lt;BR /&gt;datalines;&lt;BR /&gt;2000 2001 2002 . . 20004 . . . . 2005 2006&lt;BR /&gt;2000 2002 2003 2004 . . . . . 2005 2006 .&lt;BR /&gt;;&lt;/P&gt;</description>
    <pubDate>Wed, 09 Dec 2020 07:19:29 GMT</pubDate>
    <dc:creator>kk13</dc:creator>
    <dc:date>2020-12-09T07:19:29Z</dc:date>
    <item>
      <title>Create separate array for first observed unique number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-separate-array-for-first-observed-unique-number/m-p/704642#M216030</link>
      <description>&lt;P&gt;I have multi dimensional array of numeric numbers.&amp;nbsp; I would like to create separate multi dimensional array that shows the first observed unique numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have1;&lt;BR /&gt;input a1_1-a1_4 b1_1-b1_4 c1_1-c1_4;&lt;BR /&gt;datalines;&lt;BR /&gt;2000 2001 2002 . 2001 2004 . . 2002 2004 2005 20006&lt;BR /&gt;2000 2002 2003 2004 2003 2004 . . 2002 2005 2006 .&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data want1;&lt;BR /&gt;input fa1_1-fa1_4 fb1_1-fb1_4 fc1_1-fc1_4;&lt;BR /&gt;datalines;&lt;BR /&gt;2000 2001 2002 . . 20004 . . . . 2005 2006&lt;BR /&gt;2000 2002 2003 2004 . . . . . 2005 2006 .&lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 07:19:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-separate-array-for-first-observed-unique-number/m-p/704642#M216030</guid>
      <dc:creator>kk13</dc:creator>
      <dc:date>2020-12-09T07:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: Create separate array for first observed unique number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-separate-array-for-first-observed-unique-number/m-p/704652#M216036</link>
      <description>&lt;P&gt;You may want to check the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lepg&amp;amp;docsetTarget=n1eh4qs7mlcl6xn1omszg7bu9ubp.htm" target="_self"&gt;documentation&lt;/A&gt; to verify that the concept of arrays in sas matches your notion of arrays.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 07:52:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-separate-array-for-first-observed-unique-number/m-p/704652#M216036</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-12-09T07:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: Create separate array for first observed unique number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-separate-array-for-first-observed-unique-number/m-p/704653#M216037</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150926"&gt;@kk13&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have multi dimensional array of numeric numbers.&amp;nbsp; I would like to create separate multi dimensional array that shows the first observed unique numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have1;&lt;BR /&gt;input a1_1-a1_4 b1_1-b1_4 c1_1-c1_4;&lt;BR /&gt;datalines;&lt;BR /&gt;2000 2001 2002 . 2001 2004 . . 2002 2004 2005 20006&lt;BR /&gt;2000 2002 2003 2004 2003 2004 . . 2002 2005 2006 .&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;data want1;&lt;BR /&gt;input fa1_1-fa1_4 fb1_1-fb1_4 fc1_1-fc1_4;&lt;BR /&gt;datalines;&lt;BR /&gt;2000 2001 2002 . . 20004 . . . . 2005 2006&lt;BR /&gt;2000 2002 2003 2004 . . . . . 2005 2006 .&lt;BR /&gt;;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please be careful in creating your example data. You have values that apparently change from 20006 to 2006 and 20004 to 2004&lt;/P&gt;
&lt;P&gt;Assuming none of the values are supposed to have 3 zeroes this works for the example:&lt;/P&gt;
&lt;PRE&gt;data have1;
input a1_1-a1_4 b1_1-b1_4 c1_1-c1_4;
datalines;
2000 2001 2002 . 2001 2004 . . 2002 2004 2005 2006
2000 2002 2003 2004 2003 2004 . . 2002 2005 2006 .
;


data want;
   set have1;
   array f a1_1-a1_4 b1_1-b1_4 c1_1-c1_4;
   do i=1 to dim(f);

          if   whichn(f[i],of f(*) )  ne i
          then f[i]=.;

   end;
   drop i;
run;&lt;/PRE&gt;
&lt;P&gt;Arrays are a way to do the same to multiple variables.&lt;/P&gt;
&lt;P&gt;The function WHICHN, and a similar WHICHC for character values, returns the&amp;nbsp;&lt;STRONG&gt;first&lt;/STRONG&gt; position in a list of values where the first value is the one to search for and everything following is the list. Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; Whichn(5, 1, 2, 5) returns 3 because 5 is the third element in the list 1,2,5.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;A short hand way to say "use an array as the list" is "of arrayname(*)". The * is "all elements".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You refer to a specific variable in an array using arrayname(index) . The () could be [ ] or { }.&lt;/P&gt;
&lt;P&gt;So the above code finds the first position , or&amp;nbsp; index, of the current variable's value and if that position is different than the current index it is not the first occurrence of the value and uses the "f[i] = ." to set the value to missing.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 07:54:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-separate-array-for-first-observed-unique-number/m-p/704653#M216037</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-09T07:54:36Z</dc:date>
    </item>
  </channel>
</rss>

