<?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: Remove series of values using arrays in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Remove-series-of-values-using-arrays/m-p/634692#M188399</link>
    <description>&lt;P&gt;Assuming there is no missing value in original data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ var1-var6;
datalines;
xx 0 1 1 1 1 0
xy 1 2 1 1 1 0
xz 0 0 0 0 0 0
;
data want;
 set have;
 array x{*} var:;
 do i=2 to dim(x)-1;
  if x{i-1} in (. 1) and x{i+1} in (. 1) and x{i}=1 then x{i}=.;
 end;
 drop i;
run;
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 25 Mar 2020 10:59:59 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2020-03-25T10:59:59Z</dc:date>
    <item>
      <title>Remove series of values using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-series-of-values-using-arrays/m-p/634597#M188355</link>
      <description>&lt;P&gt;In the scenario where in my SAS dataset have series of same consecutive(count &amp;gt; 2) column values on the same row, I want to keep first and the last column values and replace with blank the ones between first and last. . Is there a way to do this using ARRAYS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id var1 var2 var3 var4 var5 var6&lt;/P&gt;
&lt;P&gt;xx 0&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired Output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id var1 var2 var3 var4 var5 var6&lt;/P&gt;
&lt;P&gt;xx 0&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 22:01:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-series-of-values-using-arrays/m-p/634597#M188355</guid>
      <dc:creator>anurak</dc:creator>
      <dc:date>2020-03-24T22:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: Remove series of values using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-series-of-values-using-arrays/m-p/634602#M188359</link>
      <description>&lt;P&gt;Here is a simple approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ var1-var6;
datalines;
xx 0 1 1 1 1 0
;

data want(drop=i c);
   set have;
   array var {*} var1-var6;
   do i=1 to dim(var);
      if      var[i]=1 then c+1;
      else if var[i]=0 then c=0;
      if c&amp;gt;2 then var[i-1]=.;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Mar 2020 22:10:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-series-of-values-using-arrays/m-p/634602#M188359</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-03-24T22:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Remove series of values using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-series-of-values-using-arrays/m-p/634604#M188361</link>
      <description>&lt;P&gt;Please try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ var1-var6;
datalines;
xx 0 1 1 1 1 0
xy 1 2 1 1 1 0
xz 0 0 0 0 0 0
;

data want;
set have;
array x var1-var6;
do i = 1 to dim(x) - 2;
	if not missing(x{i}) then do j = i + 2 to dim(x);
		if x{i} = x{j} and x{j-1} = x{j} then call missing(x{j-1});
		else leave;
		end;
	end;
drop i j;
run;

proc print data=want noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;id 	var1 	var2 	var3 	var4 	var5 	var6
xx 	0 	1 	. 	. 	1 	0
xy 	1 	2 	1 	. 	1 	0
xz 	0 	. 	. 	. 	. 	0&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 22:39:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-series-of-values-using-arrays/m-p/634604#M188361</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-03-24T22:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: Remove series of values using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-series-of-values-using-arrays/m-p/634608#M188364</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32311"&gt;@anurak&lt;/a&gt;&amp;nbsp; Prodigy Genius stats aka&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp; code made me think to find an alternative. See if this helps&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ var1-var6;
datalines;
xx 0 1 1 1 1 0
xy 1 2 1 1 1 0
xz 0 0 0 0 0 0
;

data want;
 set have;
 array x var1-var6;
 _c=1;
 do _n_=2 to dim(x);
  if x(_n_)=x(_n_-1) then _c=sum(_c,1);
  else _c=1;
  if _c&amp;gt;2 then x(_n_-1)=.;
 end;
 drop _c;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Mar 2020 23:47:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-series-of-values-using-arrays/m-p/634608#M188364</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-24T23:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: Remove series of values using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-series-of-values-using-arrays/m-p/634632#M188371</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32311"&gt;@anurak&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;In the scenario where in my SAS dataset have series of same consecutive(count &amp;gt; 2) column values on the same row, I want to keep first and the last column values and replace with blank the ones between first and last. . Is there a way to do this using ARRAYS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please note that numeric variables can't be blank, missing numeric variables contain a single dot. You can change the way missing numeric values are displayed by using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options missing= " ";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I recommend to use this only for data export, to avoid confusion.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 06:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-series-of-values-using-arrays/m-p/634632#M188371</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-03-25T06:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: Remove series of values using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-series-of-values-using-arrays/m-p/634692#M188399</link>
      <description>&lt;P&gt;Assuming there is no missing value in original data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ var1-var6;
datalines;
xx 0 1 1 1 1 0
xy 1 2 1 1 1 0
xz 0 0 0 0 0 0
;
data want;
 set have;
 array x{*} var:;
 do i=2 to dim(x)-1;
  if x{i-1} in (. 1) and x{i+1} in (. 1) and x{i}=1 then x{i}=.;
 end;
 drop i;
run;
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Mar 2020 10:59:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-series-of-values-using-arrays/m-p/634692#M188399</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-03-25T10:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Remove series of values using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-series-of-values-using-arrays/m-p/634779#M188414</link>
      <description>&lt;P&gt;I might suggest use of a special missing such as .R to indicate the values you removed instead of the generic missing. Then if you have other values that are missing for another reason such as not collected or calculated and not available you can tell latter why specific values are missing.&lt;/P&gt;
&lt;P&gt;There are 27 special missing values available: .A to .Z and ._&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you could keep track of a number of different reasons. The special missing are excluded from calculations unless using an option that indicates using the missing values.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 15:07:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-series-of-values-using-arrays/m-p/634779#M188414</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-25T15:07:18Z</dc:date>
    </item>
  </channel>
</rss>

