<?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: Retain Statement vs Array statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/314130#M68367</link>
    <description>&lt;P&gt;RW9,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure why I gave this a second look. &amp;nbsp;Here are a couple of easily fixable issues related to your program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How does FLAG ever become 2 (or 3 or 4)? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CALL MISSING will also set RESORT_ID to missing.&lt;/P&gt;</description>
    <pubDate>Thu, 24 Nov 2016 16:35:35 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-11-24T16:35:35Z</dc:date>
    <item>
      <title>Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313801#M68238</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the below code that works as a retain statement in SAS. However, I believe it could be done more effectively using an array statement and was wondering if someone could shead some light on how I could do it or even show me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA CONCAT ;
SET WEEKS_OWNERSHIPS;
BY SBR_ID;
FORMAT 				RESORT1 RESORT2 RESORT3 $500.;
RETAIN 				   RESORT1 RESORT2 RESORT3 ;

IF FIRST.SBR_ID THEN DO;

RESORT1=''; RESORT2='';RESORT3='';FLAG1=. ;

END; 

IF FLAG1 = . THEN DO
RESORT1=RESORT_ID;
END;

IF FLAG1 = 1 THEN DO
RESORT2=RESORT_ID;
END;

IF FLAG1 = 2 THEN DO
RESORT3=RESORT_ID;
END;

FLAG1+1;

IF LAST.SBR_ID THEN OUTPUT;
RUN;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Cam&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 14:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313801#M68238</guid>
      <dc:creator>CamRutherford</dc:creator>
      <dc:date>2016-11-23T14:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313808#M68240</link>
      <description>&lt;P&gt;There are more than one way to write a shorter code, thoght not specifically moe efficient:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA CONCAT ;
SET WEEKS_OWNERSHIPS;
BY SBR_ID;
FORMAT 	 RESORT1 - RESORT3 $500.;     /* equvilent to RESORT1 RESORT2 RESORT3 */
RETAIN 	 RESORT1 - RESORT3 ;           
array resx $ RESORT1 - RESORT3 ; 

IF FIRST.SBR_ID THEN DO i=1 to 3;
      resx(i) = ' ';
END; 
&lt;BR /&gt;if flag = . then RESORT1=RESORT_ID; else&lt;BR /&gt;   resx(flag +1) = RESORT_ID;

IF LAST.SBR_ID THEN OUTPUT;
RUN;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Nov 2016 15:20:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313808#M68240</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-23T15:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313810#M68242</link>
      <description>&lt;P&gt;Note that this code is not tested, if you want tested code post test data in the form of a datastep:&lt;/P&gt;
&lt;PRE&gt;data concat ;
  set weeks_ownerships;
  by sbr_id;
  array resort{3} $500;
  retain resort:;&lt;BR /&gt;  if first.sbr_id then call missing(of resort:);
  resort{sum(flag,1)}=resort_id;
  if last.sbr_id then output;
run;&lt;/PRE&gt;
&lt;P&gt;Note also that writing code all in upcase and with no indentations and such like makes your code very hard to read.&lt;/P&gt;
&lt;P&gt;Note I use sum() so that if flag=. it will become 1, if you just use + it wont.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 15:28:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313810#M68242</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-23T15:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313816#M68245</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I actually find it easier to read in capitals.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, this is my complete code and does what I need but you're array doesn't seem to do this...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA CONCAT ;
SET WEEKS_OWNERSHIPS;
BY SBR_ID;
FORMAT 		RESORT1 RESORT2 RESORT3 RESORT4 RESORT5 R1_UNIT R2_UNIT R3_UNIT R4_UNIT R5_UNIT 
						R1_OWN_DATE R2_OWN_DATE R3_OWN_DATE R4_OWN_DATE R5_OWN_DATE R1_BED R2_BED R3_BED R4_BED R5_BED
						R1_OCCUPANCY_MAX R2_OCCUPANCY_MAX R3_OCCUPANCY_MAX R4_OCCUPANCY_MAX R5_OCCUPANCY_MAX
						R1_PRIVACY_MAX R2_PRIVACY_MAX R3_PRIVACY_MAX R4_PRIVACY_MAX R5_PRIVACY_MAX R1_OWN_KEY R2_OWN_KEY
						R3_OWN_KEY R4_OWN_KEY R5_OWN_KEY R1_RESORTNAME R2_RESORTNAME R3_RESORTNAME R4_RESORTNAME R5_RESORTNAME
						R1_RESORTSTAT R2_RESORTSTAT R3_RESORTSTAT R4_RESORTSTAT R5_RESORTSTAT R1_RESORTAREA R2_RESORTAREA R3_RESORTAREA
						R4_RESORTAREA R5_RESORTAREA R1_PRIM_REG R2_PRIM_REG R3_PRIM_REG R4_PRIM_REG R5_PRIM_REG R1_SUB_REG
						R2_SUB_REG R3_SUB_REG R4_SUB_REG R5_SUB_REG R1_FIXED_FLOAT R2_FIXED_FLOAT R3_FIXED_FLOAT R4_FIXED_FLOAT R5_FIXED_FLOAT $25.
						R1_START_DT  R2_START_DT  R3_START_DT  R4_START_DT  R5_START_DT R1_END_DT R2_END_DT R3_END_DT R4_END_DT R5_END_DT	DATE9.;
RETAIN 		   RESORT1 RESORT2 RESORT3 RESORT4 RESORT5 R1_UNIT R2_UNIT R3_UNIT R4_UNIT R5_UNIT 
						R1_OWN_DATE R2_OWN_DATE R3_OWN_DATE R4_OWN_DATE R5_OWN_DATE R1_BED R2_BED R3_BED R4_BED R5_BED
						R1_OCCUPANCY_MAX R2_OCCUPANCY_MAX R3_OCCUPANCY_MAX R4_OCCUPANCY_MAX R5_OCCUPANCY_MAX
						R1_PRIVACY_MAX R2_PRIVACY_MAX R3_PRIVACY_MAX R4_PRIVACY_MAX R5_PRIVACY_MAX R1_OWN_KEY R2_OWN_KEY
						R3_OWN_KEY R4_OWN_KEY R5_OWN_KEY R1_RESORTNAME R2_RESORTNAME R3_RESORTNAME R4_RESORTNAME R5_RESORTNAME
						R1_RESORTSTAT R2_RESORTSTAT R3_RESORTSTAT R4_RESORTSTAT R5_RESORTSTAT R1_RESORTAREA R2_RESORTAREA R3_RESORTAREA
						R4_RESORTAREA R5_RESORTAREA R1_PRIM_REG R2_PRIM_REG R3_PRIM_REG R4_PRIM_REG R5_PRIM_REG R1_SUB_REG
						R2_SUB_REG R3_SUB_REG R4_SUB_REG R5_SUB_REG R1_FIXED_FLOAT R2_FIXED_FLOAT R3_FIXED_FLOAT R4_FIXED_FLOAT R5_FIXED_FLOAT
						R1_START_DT  R2_START_DT  R3_START_DT  R4_START_DT  R5_START_DT R1_END_DT R2_END_DT R3_END_DT R4_END_DT R5_END_DT ;

IF FIRST.SBR_ID THEN DO;

RESORT1=''; RESORT2=''; RESORT3=''; RESORT4=''; RESORT5='';
R1_UNIT=''; R2_UNIT=''; R3_UNIT=''; R4_UNIT=''; R5_UNIT=''; 
R1_OWN_DATE=''; R2_OWN_DATE=''; R3_OWN_DATE=''; R4_OWN_DATE=''; R5_OWN_DATE='';
R1_BED=''; R2_BED=''; R3_BED=''; R4_BED=''; R5_BED='';
R1_OCCUPANCY_MAX=''; R2_OCCUPANCY_MAX=''; R3_OCCUPANCY_MAX=''; R4_OCCUPANCY_MAX=''; R5_OCCUPANCY_MAX='';
R1_PRIVACY_MAX=''; R2_PRIVACY_MAX=''; R3_PRIVACY_MAX=''; R4_PRIVACY_MAX=''; R5_PRIVACY_MAX='';
R1_OWN_KEY=''; R2_OWN_KEY=''; R3_OWN_KEY=''; R4_OWN_KEY=''; R5_OWN_KEY=''; 
R1_RESORTNAME=''; R2_RESORTNAME=''; R3_RESORTNAME=''; R4_RESORTNAME=''; R5_RESORTNAME='';
R1_RESORTSTAT=''; R2_RESORTSTAT=''; R3_RESORTSTAT=''; R4_RESORTSTAT=''; R5_RESORTSTAT='';
R1_RESORTAREA=''; R2_RESORTAREA=''; R3_RESORTAREA=''; R4_RESORTAREA=''; R5_RESORTAREA='';
R1_PRIM_REG=''; R2_PRIM_REG=''; R3_PRIM_REG=''; R4_PRIM_REG=''; R5_PRIM_REG='';
R1_SUB_REG=''; R2_SUB_REG=''; R3_SUB_REG=''; R4_SUB_REG=''; R5_SUB_REG='';
R1_FIXED_FLOAT=''; R2_FIXED_FLOAT=''; R3_FIXED_FLOAT=''; R4_FIXED_FLOAT=''; R5_FIXED_FLOAT='';
R1_START_DT='';  R2_START_DT='';  R3_START_DT='';  R4_START_DT='';  R5_START_DT=''; 
R1_END_DT=''; R2_END_DT=''; R3_END_DT=''; R4_END_DT=''; R5_END_DT='';		FLAG1=. ;
END; 

IF FLAG1 = . THEN DO
RESORT1=RESORT_ID;			R1_OCCUPANCY_MAX=MAX_OCC;			R1_RESORTNAME=RESORT_NAME;			R1_PRIM_REG=PRIM_REGION;			R1_END_DT=ENDDT_FORMATTED;
R1_UNIT=UNIT_NO;			R1_SUB_REG=SUBREG;			R1_RESORTSTAT=RESORT_STAT;			R1_OWN_DATE=OWN_PURCH_DT;			R1_PRIVACY_MAX=PRIV_OCC;
R1_RESORTAREA=RESORT_AREA;			R1_BED=BEDROOM;			R1_FIXED_FLOAT=FIXEDFLOAT;			R1_OWN_KEY=OWNERSHIP_KEY;			R1_START_DT=STARTDT_FORMATTED;
END;

IF FLAG1 = 1 THEN DO
RESORT2=RESORT_ID;			R2_OCCUPANCY_MAX=MAX_OCC;			R2_RESORTNAME=RESORT_NAME;			R2_PRIM_REG=PRIM_REGION;			R2_END_DT=ENDDT_FORMATTED;
R2_UNIT=UNIT_NO;			R2_SUB_REG=SUBREG;			R2_RESORTSTAT=RESORT_STAT;			R2_OWN_DATE=OWN_PURCH_DT;			R2_PRIVACY_MAX=PRIV_OCC;
R2_RESORTAREA=RESORT_AREA;			R2_BED=BEDROOM;			R2_FIXED_FLOAT=FIXEDFLOAT;			R2_OWN_KEY=OWNERSHIP_KEY;			R2_START_DT=STARTDT_FORMATTED;
END;

IF FLAG1 = 2 THEN DO
RESORT3=RESORT_ID;			R3_OCCUPANCY_MAX=MAX_OCC;			R3_RESORTNAME=RESORT_NAME;			R3_PRIM_REG=PRIM_REGION;			R3_END_DT=ENDDT_FORMATTED;
R3_UNIT=UNIT_NO;			R3_SUB_REG=SUBREG;			R3_RESORTSTAT=RESORT_STAT;			R3_OWN_DATE=OWN_PURCH_DT;			R3_PRIVACY_MAX=PRIV_OCC;
R3_RESORTAREA=RESORT_AREA;			R3_BED=BEDROOM;			R3_FIXED_FLOAT=FIXEDFLOAT;			R3_OWN_KEY=OWNERSHIP_KEY;			R3_START_DT=STARTDT_FORMATTED;
END;

IF FLAG1 = 3 THEN DO
RESORT4=RESORT_ID;			R4_OCCUPANCY_MAX=MAX_OCC;			R4_RESORTNAME=RESORT_NAME;			R4_PRIM_REG=PRIM_REGION;			R4_END_DT=ENDDT_FORMATTED;
R4_UNIT=UNIT_NO;			R4_SUB_REG=SUBREG;			R4_RESORTSTAT=RESORT_STAT;			R4_OWN_DATE=OWN_PURCH_DT;			R4_PRIVACY_MAX=PRIV_OCC;
R4_RESORTAREA=RESORT_AREA;			R4_BED=BEDROOM;			R4_FIXED_FLOAT=FIXEDFLOAT;			R4_OWN_KEY=OWNERSHIP_KEY;			R4_START_DT=STARTDT_FORMATTED;
END;

IF FLAG1 = 4 THEN DO
RESORT5=RESORT_ID;			R5_OCCUPANCY_MAX=MAX_OCC;			R5_RESORTNAME=RESORT_NAME;			R5_PRIM_REG=PRIM_REGION;			R5_END_DT=ENDDT_FORMATTED;
R5_UNIT=UNIT_NO;			R5_SUB_REG=SUBREG;			R5_RESORTSTAT=RESORT_STAT;			R5_OWN_DATE=OWN_PURCH_DT;			R5_PRIVACY_MAX=PRIV_OCC;
R5_RESORTAREA=RESORT_AREA;			R5_BED=BEDROOM;			R5_FIXED_FLOAT=FIXEDFLOAT;			R5_OWN_KEY=OWNERSHIP_KEY;			R5_START_DT=STARTDT_FORMATTED;
END;

FLAG1+1;
IF LAST.SBR_ID THEN OUTPUT;
RUN;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Nov 2016 15:48:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313816#M68245</guid>
      <dc:creator>CamRutherford</dc:creator>
      <dc:date>2016-11-23T15:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313817#M68246</link>
      <description>&lt;P&gt;While you have some suggestions, I'm not sure that they increment FLAG properly.&amp;nbsp; Here's how I would try it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;array resort {5} $ 500;&lt;/P&gt;
&lt;P&gt;flag=0;&lt;/P&gt;
&lt;P&gt;do until (last.sbr_id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set weeks_ownerships;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by sbr_id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; flag + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;if flag &amp;lt;= 5 then&lt;/STRONG&gt; resort{flag} = resort&lt;STRONG&gt;_id&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop flag resort&lt;STRONG&gt;_id&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By using a DO loop to read all observations for an ID, you don't need to RETAIN resort variables and you don't need to reinitialize them to missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, PROC TRANSPOSE might be a viable approach (depending on what other variables are part of the data set).&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 16:43:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313817#M68246</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-23T16:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313820#M68248</link>
      <description>&lt;P&gt;Hi I get an error...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;1544       data concat;
1545       array resort {5} $ 500;
1546       flag=0;
1547       do until (last.sbr_id);
1548          set weeks_ownerships;
1549          by sbr_id;
1550          flag + 1;
1551          resort{flag} = resort;
ERROR: Illegal reference to the array resort.
1552       end;
1553       drop flag resort;
                     ______
                     241
ERROR 241-185: The array resort is not allowed in a DROP/KEEP/RENAME context.&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Nov 2016 15:56:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313820#M68248</guid>
      <dc:creator>CamRutherford</dc:creator>
      <dc:date>2016-11-23T15:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313823#M68249</link>
      <description>&lt;P&gt;Few questions to clarify:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) What is the purpose of assigning RESORT_ID into an array ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Should array have 3 entries only ? dynamic amount ? what are the rules ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Is FLAG a variable in the input dataset (HAVE) or a temporary variable ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;&amp;nbsp;- within your post, why not use _N_ instead FLAG, as index ?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 16:01:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313823#M68249</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-23T16:01:46Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313825#M68250</link>
      <description>&lt;P&gt;reason for the error - it should be:&lt;BR /&gt; resort{flag} = &lt;STRONG&gt;resort_id&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;DROP ...&lt;STRONG&gt;RESORT_ID&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 16:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313825#M68250</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-23T16:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313826#M68251</link>
      <description>&lt;PRE&gt;1544       DATA CONCAT;
1545       ARRAY RESORT {5} $ 500;
1546       FLAG=0;
1547       DO UNTIL (LAST.SBR_ID);
1548          SET WEEKS_OWNERSHIPS;
1549          BY SBR_ID;
1550          FLAG + 1;
1551          RESORT{FLAG} = RESORT_ID;
1552       END;
1553       DROP RESORT_ID;
1554       RUN;

ERROR: Array subscript out of range at line 1551 column 4.&lt;/PRE&gt;&lt;P&gt;Nope - still doesn't like it&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 16:08:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313826#M68251</guid>
      <dc:creator>CamRutherford</dc:creator>
      <dc:date>2016-11-23T16:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313828#M68252</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;&amp;nbsp;assumed you are going to create an array as long as number of observations in your input dataset.&lt;/P&gt;
&lt;P&gt;I don't think that this is your target. You got the error because you got index &amp;gt; 5 to enter value in the array.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 16:16:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313828#M68252</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-23T16:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313830#M68253</link>
      <description>&lt;P&gt;Sorry, my mistake.&amp;nbsp; Your variable name is actually resort_id and not resort.&amp;nbsp; I changed the original post to include the corrections.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 16:19:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313830#M68253</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-23T16:19:36Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313832#M68254</link>
      <description>&lt;P&gt;_N_ wouldn't work here.&amp;nbsp; It doesn't increment automatically just because the SET statement executes.&amp;nbsp; It actually counts something different:&amp;nbsp; how many&amp;nbsp; times has the DATA step left the DATA statement in order to execute the remaining statements in the DATA step?&amp;nbsp; So _N_=1 for all observations related to the first ID value.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 16:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313832#M68254</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-23T16:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313835#M68257</link>
      <description>&lt;P&gt;The latest results indicate that you have more than 5 observations (and therefore more than 5 RESORT_ID values) for the same person.&amp;nbsp; The real question now becomes what do you want to have happen in that case?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One possibility:&amp;nbsp; add more RESORT# variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another possibility:&amp;nbsp; ignore anything above 5 resorts per person.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another possibility:&amp;nbsp; let the program figure out how many are needed, and let the program create as many as are needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any of these is possible, but first you have to decide on the right outcome.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 16:27:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313835#M68257</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-23T16:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313837#M68259</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I only want it to pick the first 5.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Another possibility:&amp;nbsp; ignore anything above 5 resorts per person.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 16:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313837#M68259</guid>
      <dc:creator>CamRutherford</dc:creator>
      <dc:date>2016-11-23T16:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313839#M68260</link>
      <description>&lt;P&gt;OK, I added more changes to the original post to use the first 5 only.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 16:44:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313839#M68260</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-23T16:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313885#M68280</link>
      <description>&lt;P&gt;Hi Cam,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It appears you're reading in 15 variables for up to 5 rows per each SBR_ID, and creating 75 variables.&lt;/P&gt;
&lt;P&gt;If that's correct, and you want to use arrays, you can try this (un-tested) code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Keep your Retain, Format &amp;nbsp;statements, and then &amp;nbsp;create 2 arrays: ALL and RES:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Array&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; all {75} &lt;SPAN&gt;$ &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;RESORT1 RESORT2 RESORT3 RESORT4 RESORT5&lt;/P&gt;
&lt;P&gt;R1_UNIT R2_UNIT R3_UNIT R4_UNIT R5_UNIT &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;&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;&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;&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;&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;R1_OWN_DATE R2_OWN_DATE R3_OWN_DATE R4_OWN_DATE R5_OWN_DATE&lt;/P&gt;
&lt;P&gt;R1_BED R2_BED R3_BED R4_BED R5_BED ….. ;&amp;nbsp; *The 75 vars you are creating&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Array&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Res {15} Resort_ID Unit_No Own_Purch_Dt .. ;&amp;nbsp; *the 15 vars being read&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;/* Make sure the 15 variables in array RES match up 1-to-1 with each “15 subset” of array ALL */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By SBR_ID;&lt;/P&gt;
&lt;P&gt;If First.SBR_ID then DO;&lt;/P&gt;
&lt;P&gt;&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; Do k = 1 to 75;&lt;/P&gt;
&lt;P&gt;&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;&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;&amp;nbsp;&amp;nbsp; All{k} = ‘ ‘;&lt;/P&gt;
&lt;P&gt;&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; End;&lt;/P&gt;
&lt;P&gt;Flag=1;&lt;/P&gt;
&lt;P&gt;End;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* IF Flag &amp;gt; 5 then delete;&amp;nbsp; */&amp;nbsp; *Here, a check in case you have &amp;gt;5 rows/SBR_ID&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All_Stop = Flag*15;&lt;/P&gt;
&lt;P&gt;All_Start = All_Stop – 14;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do I = All_Start to All_Stop by 1;&amp;nbsp;&amp;nbsp;&amp;nbsp; *I goes from 1 to 75, in runs of 15, for each FLAG = 1,2,..5&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;&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; J = I – (Flag-1)*15;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *J goes from 1 to 15&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;&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; All{i} = Res{j};&lt;/P&gt;
&lt;P&gt;End;&lt;/P&gt;
&lt;P&gt;Flag + 1;&lt;/P&gt;
&lt;P&gt;If last.SBR_ID;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* I'm assuming you don't want all 5 rows per SBR_ID&amp;nbsp; saved */&lt;/P&gt;
&lt;P&gt;/* Drop Flag, All_start, All_Stop, i,j,k etc...&amp;nbsp;&amp;nbsp; */&lt;/P&gt;
&lt;P&gt;Run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 20:41:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/313885#M68280</guid>
      <dc:creator>Tommywhosc</dc:creator>
      <dc:date>2016-11-23T20:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/314126#M68364</link>
      <description>&lt;P&gt;Any ideas how I can do the below?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset in SAS that looks like the below but I'm looking to do the following and think an Array statement is the best way to do so...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current data&lt;/P&gt;&lt;PRE&gt;SBR_ID	Value
1234	A
1234	B
5432	A
6789	A
5432	C
1234	B
5432	B
6789	A
6789	C&lt;/PRE&gt;&lt;P&gt;I want my data set to end up like this whereby for each SBR_ID it will sum the amount of times that value appears.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;SBR_ID	A	B	C
1234	1	2	
5432	1	1	1
6789	2	0	1&lt;/PRE&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2016 15:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/314126#M68364</guid>
      <dc:creator>CamRutherford</dc:creator>
      <dc:date>2016-11-24T15:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/314130#M68367</link>
      <description>&lt;P&gt;RW9,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure why I gave this a second look. &amp;nbsp;Here are a couple of easily fixable issues related to your program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How does FLAG ever become 2 (or 3 or 4)? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CALL MISSING will also set RESORT_ID to missing.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2016 16:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/314130#M68367</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-24T16:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Statement vs Array statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/314132#M68368</link>
      <description>&lt;P&gt;&amp;nbsp;I can't test this right now, but this should be a step in the right direction:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc tabulate data=have;&lt;/P&gt;
&lt;P&gt;class sbr_id value;&lt;/P&gt;
&lt;P&gt;tables sbr_id, value=' ';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This generates a report, although it should be easy enough to add options that create a data set as the output.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2016 16:39:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Statement-vs-Array-statement/m-p/314132#M68368</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-24T16:39:41Z</dc:date>
    </item>
  </channel>
</rss>

