<?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 array function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/array-function/m-p/857149#M338659</link>
    <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am very new to the array function so I apologize in advance if my question sounds silly. Is there a way to specify the number of observations in arrays through a list? I am trying to use the following code from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;and create 100 views from a huge dataset.&amp;nbsp;I was wondering if there is a way to specify the list of percentages instead listing&amp;nbsp;&lt;STRONG&gt;(5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5).&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;data _null_ ;                                                                                                                           
  array pct p1-p20 &lt;STRONG&gt;(5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5) ;  &lt;/STRONG&gt;                                                                                                        
  lo = 1 ;                                                                                                                              
  do over pct ;                                                                                                                         
    cpct + pct ;                                                                                                                        
    hi = ceil (cpct * divide (n, 100)) ;                                                                                                
    call execute (catx (" ", cats ("data v", _i_), "/", cats ("view=v", _i_), ";")) ;                                                   
    call execute (catx (" ", "set have (firstobs=", lo, "obs=", hi, ") ;")) ;                                                           
    call execute ("run ;") ;                                                                                                            
    lo = hi + 1 ;                                                                                                                       
  end ;                                                                                                                                 
  stop ;                                                                                                                                
  set have nobs = n ;                                                                                                                   
run ;             &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thank you!&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 04 Feb 2023 08:44:22 GMT</pubDate>
    <dc:creator>AmirSari</dc:creator>
    <dc:date>2023-02-04T08:44:22Z</dc:date>
    <item>
      <title>array function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-function/m-p/857149#M338659</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am very new to the array function so I apologize in advance if my question sounds silly. Is there a way to specify the number of observations in arrays through a list? I am trying to use the following code from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;and create 100 views from a huge dataset.&amp;nbsp;I was wondering if there is a way to specify the list of percentages instead listing&amp;nbsp;&lt;STRONG&gt;(5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5).&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;data _null_ ;                                                                                                                           
  array pct p1-p20 &lt;STRONG&gt;(5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5) ;  &lt;/STRONG&gt;                                                                                                        
  lo = 1 ;                                                                                                                              
  do over pct ;                                                                                                                         
    cpct + pct ;                                                                                                                        
    hi = ceil (cpct * divide (n, 100)) ;                                                                                                
    call execute (catx (" ", cats ("data v", _i_), "/", cats ("view=v", _i_), ";")) ;                                                   
    call execute (catx (" ", "set have (firstobs=", lo, "obs=", hi, ") ;")) ;                                                           
    call execute ("run ;") ;                                                                                                            
    lo = hi + 1 ;                                                                                                                       
  end ;                                                                                                                                 
  stop ;                                                                                                                                
  set have nobs = n ;                                                                                                                   
run ;             &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thank you!&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 08:44:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-function/m-p/857149#M338659</guid>
      <dc:creator>AmirSari</dc:creator>
      <dc:date>2023-02-04T08:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: array function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-function/m-p/857151#M338660</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/102358"&gt;@AmirSari&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the abbreviated syntax&lt;/P&gt;
&lt;PRE&gt;array pct p1-p20 (&lt;STRONG&gt;20*5&lt;/STRONG&gt;) ;&lt;/PRE&gt;
&lt;P&gt;as described in the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p08do6szetrxe2n136ush727sbuo.htm#p0ipqmvg7jid2xn1408suxfvlnc5" target="_blank" rel="noopener"&gt;documentation of the ARRAY &lt;EM&gt;statement&lt;/EM&gt;&lt;/A&gt; (not: function).&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 09:10:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-function/m-p/857151#M338660</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-02-04T09:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: array function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-function/m-p/857161#M338670</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/102358"&gt;@AmirSari&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You say you want to create 100 views, but from your code it seems that the desired result is 20 views, each taking 5 pct of the full dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To achieve this, an array is not necessary, You use the array do determine the number of iterations and the number of observations selected in each iteration, and this can be done simpler, so here is a slightly modified version of your code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
  do i = 1 to 10000; 
    output; 
  end; 
run;

%let splitcount = 20;

data _null_ ;                                                                                                                           
  lo = 1 ; 
  increment = floor(divide(n, &amp;amp;splitcount)); 
  do i = 1 to &amp;amp;splitcount;
    hi = floor(lo) + (increment-1);  
    call execute (catx (" ", cats ("data v", put(i,8.)), "/", cats ("view=v",put(i,8.)), ";")) ;                                                   
    call execute (catx (" ", "set have (firstobs=", lo, "obs=", hi, ") ;")) ;                                                           
    call execute ("run ;") ;                                                                                                             
    lo = floor(hi) + 1 ;                                                                                                                      
  end ;                                                                                                                                 
  stop ;                                                                                                                                
  set have nobs = n ;                                                                                                                   
run ;             &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I wonder how you you are going to use these views, as I cannot imagine any purpose that cannot be solved simpler with a sample from the full dataset or by adding a group variable similar to the view number. Then you can pull the wanted observations with the group number:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Add group to data;
data want;    
  set have nobs=n end=eod;        
  retain group 1;
  increment = floor(divide(n, &amp;amp;splitcount)); 
  if _N_ &amp;gt; (increment * group) and not eod then group = group + 1;
run;       

* Get data from single group (same as view v3);
data d3; 
  set want (drop=increment where=(group=3));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Feb 2023 12:14:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-function/m-p/857161#M338670</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2023-02-04T12:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: array function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-function/m-p/857178#M338679</link>
      <description>Thank you for taking the time and providing an alternative solution.&lt;BR /&gt;I want 100 views each taking 1 pct but 20 views taking 5 pct each was just for example. Each view represents a dataset that I can use afterward. So, instead of splitting the dataset into 100 smaller datasets and wasting disk space, I create 100 views.</description>
      <pubDate>Sat, 04 Feb 2023 16:06:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-function/m-p/857178#M338679</guid>
      <dc:creator>AmirSari</dc:creator>
      <dc:date>2023-02-04T16:06:03Z</dc:date>
    </item>
  </channel>
</rss>

