<?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 replicate an array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/replicate-an-array/m-p/54938#M11697</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I don't know the maximum number of visits per patient, I can use : to create an array shown in the following data step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data cus2;&lt;/P&gt;&lt;P&gt;set cus1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;array V(*) visit:;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do i = 1 to dim(V);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if V(i) ^= . then visit_cnt = visit_cnt + 1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What if I want to create another array of the same number of elements as V, how to do it? Below is my failed attempt, which would help you understand what I try to accomplish:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data cus2;&lt;/P&gt;&lt;P&gt;set cus1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;array V(*) visit:;&lt;/P&gt;&lt;P&gt;array V2(*) visit2:; /*generate errors by SAS */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do i = 1 to dim(V);&lt;/P&gt;&lt;P&gt;&amp;nbsp; V2(i) = V(i) + 1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 25 Aug 2011 18:00:08 GMT</pubDate>
    <dc:creator>MarcTC</dc:creator>
    <dc:date>2011-08-25T18:00:08Z</dc:date>
    <item>
      <title>replicate an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replicate-an-array/m-p/54938#M11697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I don't know the maximum number of visits per patient, I can use : to create an array shown in the following data step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data cus2;&lt;/P&gt;&lt;P&gt;set cus1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;array V(*) visit:;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do i = 1 to dim(V);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if V(i) ^= . then visit_cnt = visit_cnt + 1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What if I want to create another array of the same number of elements as V, how to do it? Below is my failed attempt, which would help you understand what I try to accomplish:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data cus2;&lt;/P&gt;&lt;P&gt;set cus1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;array V(*) visit:;&lt;/P&gt;&lt;P&gt;array V2(*) visit2:; /*generate errors by SAS */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do i = 1 to dim(V);&lt;/P&gt;&lt;P&gt;&amp;nbsp; V2(i) = V(i) + 1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Aug 2011 18:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replicate-an-array/m-p/54938#M11697</guid>
      <dc:creator>MarcTC</dc:creator>
      <dc:date>2011-08-25T18:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: replicate an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replicate-an-array/m-p/54939#M11698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can capture the number of elements in a macro variable and use that value to set the new array dimension:&lt;/P&gt;&lt;PRE&gt;/* Make some data to play with */
data cus1;
&amp;nbsp;&amp;nbsp; array Visit{15};
&amp;nbsp;&amp;nbsp; do obs=1 to 100;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1 to dim(Visit);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Visit{i}=ranuni(1);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Visit{i} &amp;gt; .8 then Visit{i}=.;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Misses=NMISS(of Visit{*});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;
&amp;nbsp;&amp;nbsp; end;
&amp;nbsp;&amp;nbsp; drop obs i;
run;
/* Find out how many elements, store in macro variable Num */
data _null_;
&amp;nbsp;&amp;nbsp; set cus1;
&amp;nbsp;&amp;nbsp; array V{*} visit:;
&amp;nbsp;&amp;nbsp; call symputx('Num',dim(V));
&amp;nbsp;&amp;nbsp; stop;
run;
%PUT NOTE: There were &amp;amp;Num elements in the V array;

/* Now create the new array using &amp;amp;Num as the array size */
data cus2;
&amp;nbsp;&amp;nbsp; set cus1;
&amp;nbsp;&amp;nbsp; array V{*} visit:;
&amp;nbsp;&amp;nbsp; array Visit_{&amp;amp;Num} ;
&amp;nbsp;&amp;nbsp; do i = 1 to dim(V);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Visit_{i} = V{i} + 1;
&amp;nbsp;&amp;nbsp; end;
run;
&lt;/PRE&gt;&lt;P&gt;Or, you could query the dictionary tables to find out how many varibles names start with 'visit' in the cus1 data set:&lt;/P&gt;&lt;PRE&gt;proc sql noprint;
select count(*)
&amp;nbsp;&amp;nbsp; into :Num
&amp;nbsp;&amp;nbsp; from dictionary.columns
&amp;nbsp;&amp;nbsp; where LIBNAME ='WORK'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and MEMNAME='CUS1'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and lowcase (Name) like 'visit%'
;
quit;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Aug 2011 18:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replicate-an-array/m-p/54939#M11698</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2011-08-25T18:59:29Z</dc:date>
    </item>
  </channel>
</rss>

