<?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: Deriving variables based on pattern of variable values. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613800#M179311</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data tr1;
input id$       datea         dateb      datec      resa      resb      resc;
cards;
001       21277       21278      21279      0            1          0
002       21238       21239      21240      1            2          0
003       21200       21201      21202      1            0          1
;

data want;
set tr1;
array t resa--resc;
array d datea--datec;
array temp(3)  _temporary_;
max_resc=max(of t(*));
call missing(of temp(*));
do over t;
 if t then do;
  temp(_i_)=d;
 if _t&amp;gt;. and  _i_-_t&amp;gt;1 then Patt = 'I';
 else patt='C';
 _t=_i_;
 end;
end;
if n(of temp(*))=1 then patt='S';
firstdate=min(of temp(*));
lastdate=max(of temp(*));
keep id firstdate lastdate max_resc patt;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 24 Dec 2019 23:04:04 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-12-24T23:04:04Z</dc:date>
    <item>
      <title>Deriving variables based on pattern of variable values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613788#M179304</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a sample data for which I need help with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data tr1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;id$&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;datea&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dateb&amp;nbsp; &amp;nbsp; &amp;nbsp; datec&amp;nbsp; &amp;nbsp; &amp;nbsp; resa&amp;nbsp; &amp;nbsp; &amp;nbsp; resb&amp;nbsp; &amp;nbsp; &amp;nbsp; resc&lt;/P&gt;&lt;P&gt;001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21277&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21278&amp;nbsp; &amp;nbsp; &amp;nbsp; 21279&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21238&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21239&amp;nbsp; &amp;nbsp; &amp;nbsp; 21240&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;003&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21200&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21201&amp;nbsp; &amp;nbsp; &amp;nbsp; 21202&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want output data as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id$&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;max_res&amp;nbsp; &amp;nbsp; &amp;nbsp; first_dt&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;last_dt&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;patt&lt;/P&gt;&lt;P&gt;001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21278&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21278&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;S&lt;/P&gt;&lt;P&gt;002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21238&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21239&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C&lt;/P&gt;&lt;P&gt;003&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21200&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21202&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; I&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to sas programming and I am stuck with this case for a long time after trying it different ways which I have failed terribly) now&amp;nbsp; I am posting it here.Please help me to resolve the case. Any help is much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2019 21:14:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613788#M179304</guid>
      <dc:creator>skom1</dc:creator>
      <dc:date>2019-12-24T21:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving variables based on pattern of variable values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613789#M179305</link>
      <description>&lt;P&gt;Please explain the logic that let's you go from the input data to the output table.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2019 21:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613789#M179305</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-24T21:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving variables based on pattern of variable values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613791#M179306</link>
      <description>&lt;P&gt;Sure. datea, dateb and datec are collection dates for results resa,resb and resc(a,b,c are suffixes which reperesnt different timepoints they are collected.). When res_&amp;nbsp; ne 0 then first_dt is the date at which first result is collected and if there is single result for that subject ,then patt is 's'. If there are results collected continuoulsy&amp;nbsp; at every timepoint then last_dt is the date of&amp;nbsp; last time point and patt='c'.&lt;/P&gt;&lt;P&gt;if results collected at differnt timepoints and are not continuous(suffixes a,b, c etc) then patt=I and last-dt=last time point results are collected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2019 21:36:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613791#M179306</guid>
      <dc:creator>skom1</dc:creator>
      <dc:date>2019-12-24T21:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving variables based on pattern of variable values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613793#M179307</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tr1;
input id$       datea         dateb      datec      resa      resb      resc;
cards;
001       21277       21278      21279      0            1          0
002       21238       21239      21240      1            2          0
003       21200       21201      21202      1            0          1
;

data want;
set tr1;
array t resa--resc;
array d datea--datec;
array temp(3)  _temporary_;
max_resc=max(of t(*));
call missing(of temp(*));
do over t;
 if t then temp(_i_)=d;
end;
firstdate=min(of temp(*));
lastdate=max(of temp(*));
keep id firstdate lastdate max_resc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Dec 2019 22:08:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613793#M179307</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-24T22:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving variables based on pattern of variable values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613794#M179308</link>
      <description>Thank You. But I see 'Patt' variable is not derived. could you please help me with that as well.&lt;BR /&gt;if single result, patt=S&lt;BR /&gt;if results are collected continuously then Patt=C&lt;BR /&gt;if results collected intermittently then Patt = 'I'.&lt;BR /&gt;Thank you&lt;BR /&gt;</description>
      <pubDate>Tue, 24 Dec 2019 22:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613794#M179308</guid>
      <dc:creator>skom1</dc:creator>
      <dc:date>2019-12-24T22:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving variables based on pattern of variable values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613796#M179309</link>
      <description>&lt;P&gt;I think there's yet more work necessary.&amp;nbsp; I don't think the dates would come out properly yet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a similar approach for you to consider:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array res {3} resa resb resc;
array dts {3} datea dateb datec;
n_res=0;
do k=1 to 3;
&amp;nbsp; &amp;nbsp;if res{k} then do;
&amp;nbsp; &amp;nbsp; &amp;nbsp; n_res + 1;
&amp;nbsp; &amp;nbsp; &amp;nbsp; first_dt = min(first_dt, dts{k});
&amp;nbsp; &amp;nbsp; &amp;nbsp; last_dt = max(last_dt, dts{k});
&amp;nbsp; end;&lt;BR /&gt;end;
maxres = max(resa, resb, resc);
if n_res=1 then patt='S';
else if n_res = 3 then patt='C';
else if n_res = 2 then do;
&amp;nbsp; &amp;nbsp;if resb=0 then patt='I';
&amp;nbsp; &amp;nbsp;else patt = 'C';
end;
run;



&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Dec 2019 22:28:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613796#M179309</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-12-24T22:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving variables based on pattern of variable values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613799#M179310</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/304684"&gt;@skom1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Sure. datea, dateb and datec are collection dates for results resa,resb and resc(a,b,c are suffixes which reperesnt different timepoints they are collected.). When res_&amp;nbsp; ne 0 then first_dt is the date at which first result is collected and if there is single result for that subject ,then patt is 's'. If there are &lt;STRONG&gt;&lt;FONT color="#ff0000"&gt;results collected continuoulsy&amp;nbsp; at every timepoint&lt;/FONT&gt; &lt;/STRONG&gt;then last_dt is the date of&amp;nbsp; last time point and patt='c'.&lt;/P&gt;
&lt;P&gt;if results collected at differnt timepoints and are &lt;STRONG&gt;not continuous(suffixes a,b, c etc)&lt;/STRONG&gt; then patt=I and last-dt=last time point results are collected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is there a fixed number of these suffixes? Your statement above shows etc after c which sort of implies that there may be MANY of these. Your example data only shows a, b, and c but if there is a variable number then some approaches may not work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't show dat with "continuously collected at every timepoint" if resc=0 is supposed to mean not collected. So you need to provide a more concise definition of the "C" conditions. And if you actually have more than 3 res variable what happens if you have the first and second with a value other than 0, the third has a 0 and the fourth and fifth have values other than 0?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2019 22:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613799#M179310</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-24T22:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving variables based on pattern of variable values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613800#M179311</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data tr1;
input id$       datea         dateb      datec      resa      resb      resc;
cards;
001       21277       21278      21279      0            1          0
002       21238       21239      21240      1            2          0
003       21200       21201      21202      1            0          1
;

data want;
set tr1;
array t resa--resc;
array d datea--datec;
array temp(3)  _temporary_;
max_resc=max(of t(*));
call missing(of temp(*));
do over t;
 if t then do;
  temp(_i_)=d;
 if _t&amp;gt;. and  _i_-_t&amp;gt;1 then Patt = 'I';
 else patt='C';
 _t=_i_;
 end;
end;
if n(of temp(*))=1 then patt='S';
firstdate=min(of temp(*));
lastdate=max(of temp(*));
keep id firstdate lastdate max_resc patt;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Dec 2019 23:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613800#M179311</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-24T23:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving variables based on pattern of variable values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613801#M179312</link>
      <description>&lt;P&gt;Yes. there are more suffixes(a to h). "C' is only populated when results are collected at all successive timepoints. In the case you specified, if first, second results ne '0' and thirds=0 and 4th, 5th are ne '0' , patt = 'I'.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2019 23:21:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613801#M179312</guid>
      <dc:creator>skom1</dc:creator>
      <dc:date>2019-12-24T23:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving variables based on pattern of variable values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613802#M179313</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tr1;
input id$       datea         dateb      datec      resa      resb      resc;
cards;
001       21277       21278      21279      0            1          0
002       21238       21239      21240      1            2          0
003       21200       21201      21202      1            0          1
;
run;


data want;
set tr1;

array dt date:;
array re  res:;


do i=1 to dim(re);
if re[i] &amp;gt; 0 then do;
	firstdt=dt[i];
	ind1=i;
	leave;
end;
end;

do j=dim(re) to 1 by -1;
if re[j] &amp;gt; 0 then do;
	lastdt=dt[j];
	ind2=j;
	leave;
end;
end;

max_res=max(of re[*]);
 
if ind1=ind2 then	
	patt='S';
else if ind2=ind1+1 then
	patt='C';
else 	patt='I';

keep id max_res firstdt lastdt patt;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Dec 2019 23:46:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613802#M179313</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2019-12-24T23:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving variables based on pattern of variable values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613809#M179318</link>
      <description>&lt;P&gt;You can make an array parallel to RESA,RESB,RESC in which each&amp;nbsp;array element&amp;nbsp;(call it _RES{i}) is missing whenever the analogous RES variable is zero, and is set to equal&amp;nbsp;i otherwise.&amp;nbsp;&amp;nbsp; So for the third obs the _RES array would be {1,.,3}.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then apply the MAX, MIN, and N functions to _RES to identify the element of the corresponding DATE array to use for first_dt, last_dt, and patt:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id$       datea         dateb      datec      resa      resb      resc;
cards;
001       21277       21278      21279      0            1          0
002       21238       21239      21240      1            2          0
003       21200       21201      21202      1            0          1
;


data want (drop=i _r:);
  set have;
  array dat {*} date: ;
  array res {*} res:  ;

  array _res {3};   /*Gets a missing value when RES=0, or else the element index when RES^=0*/
  do i=1 to 3;
    if res{i}^=0 then _res{i}=i;
  end;

  first_dt=dat{min(of _res{*})};
  last_dt=dat{max(of _res{*})};

  if first_dt=last_dt then patt='S';
  else if max(of _res{*}) = min(of _res{*}) + n(of _res{*})-1 then patt='C';
  else patt='I';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Dec 2019 04:24:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613809#M179318</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-12-25T04:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving variables based on pattern of variable values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613835#M179335</link>
      <description>Thank you for the reply. The dataset I am currently working on have 8 dates and result variables. When I am trying to use your code it says array is out of range at _res{i}. Can you help me debug. Thanks</description>
      <pubDate>Wed, 25 Dec 2019 20:25:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613835#M179335</guid>
      <dc:creator>skom1</dc:creator>
      <dc:date>2019-12-25T20:25:36Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving variables based on pattern of variable values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613847#M179339</link>
      <description>&lt;P&gt;Two comments:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;You report an error message, but it is unaccompanied by a copy of the problem program, or the log containing the message.&amp;nbsp; Help us help you by providing information needed to diagnose and prescribe.&lt;/LI&gt;
&lt;LI&gt;HOWEVER ... you refer to having 8 RES (and DATE) variables, so that means your arrays (including _RES) should all have 8 elements.&amp;nbsp; (My example defined _RES as having only 3).&amp;nbsp; And any do loops from 1 to 3 should be changed to loop from 1 to 8.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2019 04:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613847#M179339</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-12-26T04:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving variables based on pattern of variable values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613973#M179405</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;here is the program and its error message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;26 data ZRS1 /*(drop=i _r:)*/;&lt;BR /&gt;27 set ZRS;&lt;BR /&gt;28 array dat {*} date: ;&lt;BR /&gt;29 array res {*} res: ;&lt;BR /&gt;30&lt;BR /&gt;31 array _res {8} ;&lt;BR /&gt;32 do i=1 to 8;&lt;BR /&gt;33 mindt = min(of dat[*]);&lt;BR /&gt;34 maxdt = max(of dat[*]);&lt;BR /&gt;35 if res{i}^='0' then _res{i}=i;&lt;BR /&gt;36 end;&lt;BR /&gt;37&lt;BR /&gt;38 if _res{i}=. then do;&lt;BR /&gt;39&lt;BR /&gt;40 first_dt =mindt;&lt;BR /&gt;41 last_dt = maxdt;&lt;BR /&gt;42 end;&lt;BR /&gt;43&lt;BR /&gt;44 else if _res{i} ne . then do;&lt;BR /&gt;45 first_dt=dat{min(of _res{*})};&lt;BR /&gt;46 last_dt=dat{max(of _res{*})};end;&lt;BR /&gt;47&lt;BR /&gt;48&lt;BR /&gt;49 if first_dt=last_dt then patt='S';&lt;BR /&gt;50 else if max(of _res{*}) = min(of _res{*}) + n(of _res{*})-1 then patt='C';&lt;BR /&gt;51 else patt='I';&lt;BR /&gt;52 run;&lt;/P&gt;&lt;P&gt;ERROR: Array subscript out of range at line 38 column 5.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank You.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2019 20:45:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613973#M179405</guid>
      <dc:creator>skom1</dc:creator>
      <dc:date>2019-12-26T20:45:29Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving variables based on pattern of variable values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613978#M179406</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure how you got from my program to yours, but it is not close enough for me to give compact answers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Strip your program back to mine.&amp;nbsp; Make only the changes necessary to accommodate 8 RES values rather than the 3 in my suggestion.&amp;nbsp; Then if you have a problem report back to us.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2019 20:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613978#M179406</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-12-26T20:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving variables based on pattern of variable values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613988#M179409</link>
      <description>&lt;P&gt;At the end of an iterated do loop such as&lt;/P&gt;
&lt;P&gt;do I= 1 to 8;&lt;/P&gt;
&lt;P&gt;you find the value of I to be one more than the maximum value (unless you have some code to skip out of the loop early).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So in your code (slightly reformatted for legibility)&lt;/P&gt;
&lt;PRE&gt;32 do i=1 to 8;
33    mindt = min(of dat[*]);
34    maxdt = max(of dat[*]);
35    if res{i}^='0' then _res{i}=i;
36 end;
37
38 if _res{i}=. then do;&lt;/PRE&gt;
&lt;P&gt;line 38 uses the value of the index variable I after ending the loop and will have a value of 9. So the array index is out of range as you define the array _res to have 8 elements. Line 44 will have the same issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you will get the exact same value for&lt;/P&gt;
&lt;PRE&gt;33 mindt = min(of dat[*]); 
34 maxdt = max(of dat[*]); &lt;/PRE&gt;
&lt;P&gt;So these really do not need to be in any sort of loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2019 21:54:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/613988#M179409</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-26T21:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving variables based on pattern of variable values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/614166#M179475</link>
      <description>&lt;P&gt;Got it. Thank You very much&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2019 23:43:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deriving-variables-based-on-pattern-of-variable-values/m-p/614166#M179475</guid>
      <dc:creator>skom1</dc:creator>
      <dc:date>2019-12-27T23:43:12Z</dc:date>
    </item>
  </channel>
</rss>

