<?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: Convert list to an array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-list-to-an-array/m-p/765538#M242491</link>
    <description>&lt;P&gt;Thank you all.&lt;/P&gt;</description>
    <pubDate>Thu, 02 Sep 2021 03:43:29 GMT</pubDate>
    <dc:creator>SK_11</dc:creator>
    <dc:date>2021-09-02T03:43:29Z</dc:date>
    <item>
      <title>Convert list to an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-list-to-an-array/m-p/765525#M242481</link>
      <description>&lt;P&gt;I would like to convert the following list into 2D Array.&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 50pt;" border="0" width="67" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="67" height="19" style="height: 14.4pt; width: 50pt;"&gt;a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" style="height: 14.4pt;"&gt;b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" style="height: 14.4pt;"&gt;c&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" style="height: 14.4pt;"&gt;d&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" style="height: 14.4pt;"&gt;e&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;The output should look like&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 100pt;" border="0" width="134" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="67" height="19" style="height: 14.4pt; width: 50pt;"&gt;a&lt;/TD&gt;
&lt;TD width="67" style="width: 50pt;"&gt;b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" style="height: 14.4pt;"&gt;c&lt;/TD&gt;
&lt;TD&gt;d&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" style="height: 14.4pt;"&gt;e&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 150pt;" border="0" width="201" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="67" height="19" style="height: 14.4pt; width: 50pt;"&gt;a&lt;/TD&gt;
&lt;TD width="67" style="width: 50pt;"&gt;b&lt;/TD&gt;
&lt;TD width="67" style="width: 50pt;"&gt;c&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" style="height: 14.4pt;"&gt;d&lt;/TD&gt;
&lt;TD&gt;e&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;The solution should work for any number of columns and rows.&lt;/P&gt;
&lt;P&gt;Any help would be highly appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 01:08:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-list-to-an-array/m-p/765525#M242481</guid>
      <dc:creator>SK_11</dc:creator>
      <dc:date>2021-09-02T01:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: Convert list to an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-list-to-an-array/m-p/765531#M242485</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;The solution should work for any number of columns and rows.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;What defines the dimensions of the array?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 02:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-list-to-an-array/m-p/765531#M242485</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-09-02T02:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: Convert list to an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-list-to-an-array/m-p/765532#M242486</link>
      <description>&lt;P&gt;What do you mean by "array"?&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you talking about and ARRAY in a SAS data step?&amp;nbsp; What variables to you want to use the ARRAY statement to reference?&amp;nbsp; Once you have the list of variables it does not matter what set of dimensions you use.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or are you using PROC IML?&amp;nbsp; Sounds like you just want to reshape an single column array into a multi-column array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or are you talking about create a SAS dataset (which NOT an array).&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 02:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-list-to-an-array/m-p/765532#M242486</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-02T02:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Convert list to an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-list-to-an-array/m-p/765533#M242487</link>
      <description>&lt;P&gt;try this code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length a $1;
  input a $;
cards;
a
b
c
d
e
;
run;


data want;
  set have end=eof;
  /* specify number of elements */
  array x{3} $1;
  retain x:;
  /* initialization */
  if mod(_n_,dim(x))=1 then do;
    do _i=1 to dim(x);
      x{_i}='';
    end;
  end;
  /* value to array */
  _ord=mod(_n_,dim(x));
  x{ifn(_ord=0,dim(x),_ord)}=a;
  /* output obs */
  if eof then do;
    output;
  end; else 
  if mod(_n_,dim(x))=0 then do;
    output;
  end;
  drop a _:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 02:45:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-list-to-an-array/m-p/765533#M242487</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-09-02T02:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: Convert list to an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-list-to-an-array/m-p/765534#M242488</link>
      <description>&lt;P&gt;If you are talking about converting one &lt;STRONG&gt;dataset&lt;/STRONG&gt; to another &lt;STRONG&gt;dataset&lt;/STRONG&gt; then here is simple method, but I wouldn't call either dataset an &lt;STRONG&gt;array&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just specify the number of new variables (columns) you want to create.&amp;nbsp; The data step will generate the appropriate number of observations (rows) based on how many observations are in the input dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input var $;
cards;
a
b
c
d
e
;

%let cols=3;
data want;
  do col=1 to &amp;amp;cols until(eof);
    set have end=eof;
    array cols $8 col1-col&amp;amp;cols;
    cols[col]=var;
  end;
  drop col var;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    col1    col2    col3

 1      a       b       c
 2      d       e

&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Sep 2021 02:54:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-list-to-an-array/m-p/765534#M242488</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-02T02:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: Convert list to an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-list-to-an-array/m-p/765536#M242489</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
do t = "a", "b", "c", "d", "e";
    output;
    end;
run;

data _null_;
if 0 then set have nobs=nobs;
call symputx("n", floor(sqrt(nobs))); /* replace floor by ceil for more columns */
stop;
run; 

data want;
array tt{&amp;amp;n.} $;
do i = 1 to &amp;amp;n. until(done);
    set have end=done;
    tt{i} = t;
    end;
keep tt:;
run;

proc print data=want; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_0-1630551891550.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63229i0E4C86FD9424DC44/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PGStats_0-1630551891550.png" alt="PGStats_0-1630551891550.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 03:06:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-list-to-an-array/m-p/765536#M242489</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-09-02T03:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: Convert list to an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-list-to-an-array/m-p/765538#M242491</link>
      <description>&lt;P&gt;Thank you all.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 03:43:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-list-to-an-array/m-p/765538#M242491</guid>
      <dc:creator>SK_11</dc:creator>
      <dc:date>2021-09-02T03:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: Convert list to an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-list-to-an-array/m-p/765621#M242526</link>
      <description>&lt;P&gt;It is IML 's thing .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length a $1;
  input a $;
cards;
a
b
c
d
e
;
run;


proc iml;
use have;
read all var _all_ into x;
close;

want=shape(x,3,2,' ');
print want;

want=shape(x,2,3,' ');
print want;


quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Sep 2021 12:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-list-to-an-array/m-p/765621#M242526</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-09-02T12:45:47Z</dc:date>
    </item>
  </channel>
</rss>

