<?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: array name in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592583#M8062</link>
    <description>&lt;P&gt;You normally get the answer you need faster if you supply a SAS data step creating a sample data set Have and then show exactly how the desired output should look like if using the data from Have.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;
data have;
  input country $ '1990'n '1991'n '1992'n '1993'n; 
  datalines;
Burundi 3.01 . . 0.66 
Canada . 0.12 . 2.11 
;
run;

data want;
  set have;
  array n {*} '1990'n-'2014'n;
  do i=1 to dim(n)-1;
    if n[i]=. then
      /* pick the next non-missing value */
      do j=i+1 to dim(n);
        if not missing(n[j]) then 
          do;
            n[i]= n[j];
            leave;
          end;
      end;
  end;
run;

proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 30 Sep 2019 08:21:49 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2019-09-30T08:21:49Z</dc:date>
    <item>
      <title>array name</title>
      <link>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592549#M8058</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my data is something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;country&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1990&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1991&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1992&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1993&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Burundi&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3.01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.66&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Canada&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2.11&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and now I want to replace the missing value by the follow non-missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my code is&lt;/P&gt;
&lt;P&gt;data replace1;&lt;BR /&gt;set co2_emission_id;&lt;BR /&gt;array [*] '1990'n-'2014'n;&lt;BR /&gt;do i=1990 to dim(''n);&lt;BR /&gt;if ''n{i}=. then ''n{i}= ''n{i+1};&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think there is a name needed between array and [*] so I can modify the do loop.&amp;nbsp; But my data variable names are numbers so I don't know what I should put there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May I have a suggestion for that?&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2019 03:24:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592549#M8058</guid>
      <dc:creator>YangYY</dc:creator>
      <dc:date>2019-09-30T03:24:36Z</dc:date>
    </item>
    <item>
      <title>Re: array name</title>
      <link>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592552#M8059</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/284230"&gt;@YangYY&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below code with fixes for all the syntax errors in what you've posted.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data replace1;
  set co2_emission_id;
  array n {*} '1990'n-'2014'n;

  do i=1 to dim(n)-1;
    if n[i]=. then n[i]= n{i+1};
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Sep 2019 03:58:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592552#M8059</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-09-30T03:58:41Z</dc:date>
    </item>
    <item>
      <title>Re: array name</title>
      <link>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592565#M8060</link>
      <description>Thank you for your reply!&lt;BR /&gt;The code works but the output is&lt;BR /&gt;country       1990       1991        1992       1993   &lt;BR /&gt;&lt;BR /&gt;Burundi        3.01         .                0.66           0.66   &lt;BR /&gt;&lt;BR /&gt;Canada          0.12          0.12            2.11         2.11&lt;BR /&gt;&lt;BR /&gt;The first missing value would not be replaced. How should I modify my code?&lt;BR /&gt;&lt;BR /&gt;Best wishes</description>
      <pubDate>Mon, 30 Sep 2019 05:30:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592565#M8060</guid>
      <dc:creator>YangYY</dc:creator>
      <dc:date>2019-09-30T05:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: array name</title>
      <link>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592583#M8062</link>
      <description>&lt;P&gt;You normally get the answer you need faster if you supply a SAS data step creating a sample data set Have and then show exactly how the desired output should look like if using the data from Have.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;
data have;
  input country $ '1990'n '1991'n '1992'n '1993'n; 
  datalines;
Burundi 3.01 . . 0.66 
Canada . 0.12 . 2.11 
;
run;

data want;
  set have;
  array n {*} '1990'n-'2014'n;
  do i=1 to dim(n)-1;
    if n[i]=. then
      /* pick the next non-missing value */
      do j=i+1 to dim(n);
        if not missing(n[j]) then 
          do;
            n[i]= n[j];
            leave;
          end;
      end;
  end;
run;

proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2019 08:21:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592583#M8062</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-09-30T08:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: array name</title>
      <link>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592594#M8063</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input country $ _1990 _1991 _1992 _1993;
datalines;   
Burundi 3.01 . . 0.66   
Canada . 0.12 . 2.11
;

data want;
set have;
array n {*} _:;
do i = dim(n) - 1 to 1 by -1;
  n{i} = coalesce(n{i},n{i+1});
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that coding is much easier when one avoids the stupid name literals.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2019 08:57:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592594#M8063</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-30T08:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: array name</title>
      <link>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592715#M8065</link>
      <description>&lt;P&gt;The name you use for the array is any valid SAS name just pick one that it not already used by a real variable in your dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Normal SAS names start with a letter or underscore, have a maximum length of 32 characters (bytes actually) and contain only letters, digits or underscore.&amp;nbsp; &amp;nbsp;You might want to avoid names that SAS uses for other things, like functions, but you can still use those names, you just won't be able to call that function since any reference will be assumed to be to the array.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2019 15:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592715#M8065</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-30T15:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: array name</title>
      <link>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592887#M8072</link>
      <description>OK and Thank you it works perfect this time!</description>
      <pubDate>Tue, 01 Oct 2019 01:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592887#M8072</guid>
      <dc:creator>YangYY</dc:creator>
      <dc:date>2019-10-01T01:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: array name</title>
      <link>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592888#M8073</link>
      <description>&lt;P&gt;Thanks. I do like the code&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;posted better though. Here the code with a tweak so it also works with your SAS name literals.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;

data have;
  input country $ '1990'n '1991'n '1992'n '1993'n;
  datalines;
Burundi 3.01 . . 0.66 
Canada . 0.12 . 2.11 
;

data want;
  set have;
  array n {*} '1990'n-'2014'n;;
  do i = dim(n) - 1 to 1 by -1;
    n{i} = coalesce(n{i},n{i+1});
  end;

  drop i;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Oct 2019 01:44:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592888#M8073</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-10-01T01:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: array name</title>
      <link>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592891#M8074</link>
      <description>Hi,Thank you for your reply and your code also work perfectly. But since I am new to SAS, the post I accept as solution is easier to understand to me.  I just want to let you know your code is awesome and I appreciated for your answer!</description>
      <pubDate>Tue, 01 Oct 2019 02:23:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/array-name/m-p/592891#M8074</guid>
      <dc:creator>YangYY</dc:creator>
      <dc:date>2019-10-01T02:23:02Z</dc:date>
    </item>
  </channel>
</rss>

