<?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 know when a specifiq calue is changing between columns in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/know-when-a-specifiq-calue-is-changing-between-columns/m-p/589651#M14921</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input contract classe_201801 $ classe_201802 $ classe_201803 $ classe_201804 $ classe_201805 $ classe_201806 $ 
classe_201807 $ classe_201808 $ classe_201809 $ classe_201810 $ classe_201811 $ classe_201812 $ ;
datalines;
111111 A B B B A A A B B B B C
 ;
run;

%macro mc_histo_rece ;

%let N=1 ;

data want;
set have ;
array array_classe(12) classe_:;
%do i=1 %to 11 ;
	%let suivant=%eval(&amp;amp;i+1) ;
	if array_classe(&amp;amp;i) ne "B" and array_classe(&amp;amp;suivant) eq "B" 
	then do ;
		begin_&amp;amp;N = substr(vname(array_classe(&amp;amp;suivant)),8,6) ; 
	%let N = %eval(&amp;amp;N + 1) ;
	end ;
%end ;
run;

%mend ;

%mc_histo_rece ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I need to obtain 2 new column, one column named begin_1 that holds 2018 and one column named begin_2 that holds 201808&lt;/P&gt;&lt;P&gt;because 201802 is the first begining of periode B and 201808 is the begining of the second periode B&lt;/P&gt;&lt;P&gt;thanks a lot in advance for your help&lt;/P&gt;&lt;P&gt;Nasser&lt;/P&gt;</description>
    <pubDate>Wed, 18 Sep 2019 13:49:17 GMT</pubDate>
    <dc:creator>Nasser_DRMCP</dc:creator>
    <dc:date>2019-09-18T13:49:17Z</dc:date>
    <item>
      <title>know when a specifiq calue is changing between columns</title>
      <link>https://communities.sas.com/t5/New-SAS-User/know-when-a-specifiq-calue-is-changing-between-columns/m-p/589651#M14921</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input contract classe_201801 $ classe_201802 $ classe_201803 $ classe_201804 $ classe_201805 $ classe_201806 $ 
classe_201807 $ classe_201808 $ classe_201809 $ classe_201810 $ classe_201811 $ classe_201812 $ ;
datalines;
111111 A B B B A A A B B B B C
 ;
run;

%macro mc_histo_rece ;

%let N=1 ;

data want;
set have ;
array array_classe(12) classe_:;
%do i=1 %to 11 ;
	%let suivant=%eval(&amp;amp;i+1) ;
	if array_classe(&amp;amp;i) ne "B" and array_classe(&amp;amp;suivant) eq "B" 
	then do ;
		begin_&amp;amp;N = substr(vname(array_classe(&amp;amp;suivant)),8,6) ; 
	%let N = %eval(&amp;amp;N + 1) ;
	end ;
%end ;
run;

%mend ;

%mc_histo_rece ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I need to obtain 2 new column, one column named begin_1 that holds 2018 and one column named begin_2 that holds 201808&lt;/P&gt;&lt;P&gt;because 201802 is the first begining of periode B and 201808 is the begining of the second periode B&lt;/P&gt;&lt;P&gt;thanks a lot in advance for your help&lt;/P&gt;&lt;P&gt;Nasser&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2019 13:49:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/know-when-a-specifiq-calue-is-changing-between-columns/m-p/589651#M14921</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2019-09-18T13:49:17Z</dc:date>
    </item>
    <item>
      <title>Re: know when a specifiq calue is changing between columns</title>
      <link>https://communities.sas.com/t5/New-SAS-User/know-when-a-specifiq-calue-is-changing-between-columns/m-p/589675#M14925</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/147725"&gt;@Nasser_DRMCP&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I need to obtain 2 new column, one column named begin_1 that holds 2018 and one column named begin_2 that holds 201808&lt;/P&gt;
&lt;P&gt;because 201802 is the first begining of periode B and 201808 is the begining of the second periode B&lt;/P&gt;
&lt;P&gt;thanks a lot in advance for your help&lt;/P&gt;
&lt;P&gt;Nasser&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why do you need new variables? Assuming that by 201802 you mean the variable classe_201802 you already have the variable. And since you are only asking to add new variables with apparently the existing value then there is not reason to add variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also your subject line says "changing between columns". So what do you want to check for changing? What does the expected output for example data look like?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And your macro is almost certainly not needed. A simple&lt;/P&gt;
&lt;P&gt;array begin (12) $6.&amp;nbsp;;&lt;/P&gt;
&lt;P&gt;do I= 1 to dim(array_classe);&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token keyword"&gt;&amp;nbsp;&amp;nbsp; if&lt;/SPAN&gt; array_classe&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;i&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;ne&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;"B"&lt;/SPAN&gt; and array_classe&lt;SPAN class="token punctuation"&gt;(I+1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;eq&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;"B"&lt;/SPAN&gt; then begin(I) &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;substr&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;vname&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;array_classe&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;I+1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;8&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;6&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;Though you should be able to calculate the value of begin from the value of the I index variable as well.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2019 14:35:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/know-when-a-specifiq-calue-is-changing-between-columns/m-p/589675#M14925</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-18T14:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: know when a specifiq calue is changing between columns</title>
      <link>https://communities.sas.com/t5/New-SAS-User/know-when-a-specifiq-calue-is-changing-between-columns/m-p/589676#M14926</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you mean something like that (it's more general when there may be more beginnings or none):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input contract classe_201801 $ classe_201802 $ classe_201803 $ classe_201804 $ classe_201805 $ classe_201806 $ 
classe_201807 $ classe_201808 $ classe_201809 $ classe_201810 $ classe_201811 $ classe_201812 $ ;
datalines;
111111 A B B B A A A B B B B C
222222 B B B B B B B B B B B C
333333 A A A A A A A A A A A A
444444 A B A B A B A B A B A B
555555 B A B A B A B A B A B A 
 ;
run;


data want;
set have ;
_fake_ = " ";
array array_classe[0:12] _fake_ classe_:;

array begin_[6] $ 32;

j=0;
do i = 1 to hbound(array_classe);
  if array_classe[i] = "B" and  array_classe[i-1] ne "B" then 
    do;
      j+1;
      begin_[j] = vname(array_classe[i]);
    end;
end;

drop i j _fake_;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2019 14:37:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/know-when-a-specifiq-calue-is-changing-between-columns/m-p/589676#M14926</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-09-18T14:37:06Z</dc:date>
    </item>
  </channel>
</rss>

