<?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 load a single observation into an array? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-load-a-single-observation-into-an-array/m-p/914233#M360245</link>
    <description>&lt;P&gt;So to load just the second observation from a dataset you can use FIRSTOBS= and OBS= dataset options.&amp;nbsp; To load "into an array" just use the same variable names when listing the members of the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if _n_= 1 then do;
    set have (firstobs=2 obs=2) ;
    array myarray varr1-varr3;
  end;
  /* Now what do you want to do ? */
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 02 Feb 2024 15:48:51 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-02-02T15:48:51Z</dc:date>
    <item>
      <title>How to load a single observation into an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-load-a-single-observation-into-an-array/m-p/914164#M360230</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a simple dataset. Please see below.&lt;/P&gt;&lt;P&gt;How can I load the second observation into an array using a second data step?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile DATALINES dsd missover;&lt;BR /&gt;input varr1 varr2 varr3;&lt;BR /&gt;CARDS;&lt;BR /&gt;1, 2, 3&lt;BR /&gt;2, 3, 4&lt;BR /&gt;5, 4&lt;BR /&gt;4, 3&lt;BR /&gt;9, 4, 1&lt;BR /&gt;6,&lt;BR /&gt;;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 06:38:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-load-a-single-observation-into-an-array/m-p/914164#M360230</guid>
      <dc:creator>TacoLover</dc:creator>
      <dc:date>2024-02-02T06:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to load a single observation into an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-load-a-single-observation-into-an-array/m-p/914167#M360232</link>
      <description>&lt;P&gt;With SAS9.4 an array is nothing more than a logical pointer to a collection of variables. Only Viya CASL introduces an Array data type for list processing.&lt;/P&gt;
&lt;P&gt;With SAS 9.4/Viya Compute here how an array definition looks like.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile DATALINES dsd missover;
  input varr1 varr2 varr3;
  array myarr{*} varr1 - varr3;
  CARDS;
1, 2, 3
2, 3, 4
5, 4
4, 3
9, 4, 1
6,
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can also use the array statement to define the variables and then use it in the input statement. The created dataset will just contain variables varr1 to varr2.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile DATALINES dsd missover;
  array myarr{*} varr1 - varr3;
  input myarr[*];
  CARDS;
1, 2, 3
2, 3, 4
5, 4
4, 3
9, 4, 1
6,
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 07:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-load-a-single-observation-into-an-array/m-p/914167#M360232</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-02-02T07:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to load a single observation into an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-load-a-single-observation-into-an-array/m-p/914174#M360233</link>
      <description>&lt;P&gt;Why only the second observation? What are you going to do?&lt;/P&gt;
&lt;P&gt;Probably just as well to "load" each observation into the array and just use it conditionally.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 09:27:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-load-a-single-observation-into-an-array/m-p/914174#M360233</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-02-02T09:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to load a single observation into an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-load-a-single-observation-into-an-array/m-p/914183#M360238</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for using a data step to provide the data, that helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would agree with others that some context would help as to why you require a particular observation to be loaded into an array. If you could explain this then you might be presented with another approach that is considered better practice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having said that, the following code might be one way you could try it (array statement copied from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;).&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;NB.&lt;/STRONG&gt; The use of the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;stop&lt;/FONT&gt;&amp;nbsp;statement can help prevent a data step from&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;running&amp;nbsp;&lt;SPAN&gt;infinitely when the &lt;FONT face="courier new,courier"&gt;point=&lt;/FONT&gt; option is being used.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile DATALINES dsd missover;
  input varr1 varr2 varr3;
  CARDS;
1, 2, 3
2, 3, 4
5, 4
4, 3
9, 4, 1
6,
;


%let obs_num = 2;

data want(drop = i);
  array myarr{*} varr1 - varr3;
  
  obs_num = &amp;amp;obs_num;
  set have point = obs_num;
  
  do i = 1 to dim(myarr);
    put myarr[i]=;
  end;
  
  output;
  
  /* use stop as point= option is being used */
  stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The log shows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; 85         %let obs_num = 2;
 86         
 87         data want(drop = i);
 88           array myarr{*} varr1 - varr3;
 89           obs_num = &amp;amp;obs_num;
 90           set have point = obs_num;
 91         
 92           do i = 1 to dim(myarr);
 93             put myarr[i]=;
 94           end;
 95         
 96           output;
 97           stop;
 98         run;
 
 varr1=2
 varr2=3
 varr3=4
 NOTE: The data set WORK.WANT has 1 observations and 3 variables.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 10:18:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-load-a-single-observation-into-an-array/m-p/914183#M360238</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2024-02-02T10:18:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to load a single observation into an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-load-a-single-observation-into-an-array/m-p/914217#M360241</link>
      <description>&lt;P&gt;Loading an observation into an array is trivial.&amp;nbsp; So just to make sure we are talking apples to apples, here are some points to consider.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you expect the array to be saved somehow?&amp;nbsp; In almost all cases, array definitions disappear as soon as the DATA step ends.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really have just 3 variables, or could there be hundreds (or thousands)?&amp;nbsp; How will you determine the number of variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you need the array values to be available when you process the first observation in the data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When the program reads the 3rd observation, you may be replacing the contents of the array.&amp;nbsp; Does that sound OK?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The already-asked question of what do you plan to do from here likely becomes relevant.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 14:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-load-a-single-observation-into-an-array/m-p/914217#M360241</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2024-02-02T14:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to load a single observation into an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-load-a-single-observation-into-an-array/m-p/914233#M360245</link>
      <description>&lt;P&gt;So to load just the second observation from a dataset you can use FIRSTOBS= and OBS= dataset options.&amp;nbsp; To load "into an array" just use the same variable names when listing the members of the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if _n_= 1 then do;
    set have (firstobs=2 obs=2) ;
    array myarray varr1-varr3;
  end;
  /* Now what do you want to do ? */
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Feb 2024 15:48:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-load-a-single-observation-into-an-array/m-p/914233#M360245</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-02T15:48:51Z</dc:date>
    </item>
  </channel>
</rss>

