<?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 iteration in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/iteration/m-p/670047#M201089</link>
    <description>&lt;P&gt;By using the below code I am trying to create 2 records. First record should be "JG" and other has to be "VC", but I only get "JG" in 2 records.&lt;BR /&gt;Can you help me how to create this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data sub1;&lt;BR /&gt;subj = "201";&lt;BR /&gt;armcd = "JGVC";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%let k =1;&lt;/P&gt;&lt;P&gt;data sub2;&lt;BR /&gt;set sub1;&lt;BR /&gt;armlen = length(armcd);&lt;BR /&gt;do i = 1 to armlen/2;&lt;BR /&gt;length split_armcd $200;&lt;BR /&gt;split_armcd = substr(armcd,&amp;amp;k.,2);&lt;BR /&gt;split_armcdn = i;&lt;BR /&gt;%let k=%eval(&amp;amp;k + 2);&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Kumar.&lt;/P&gt;</description>
    <pubDate>Fri, 17 Jul 2020 03:51:41 GMT</pubDate>
    <dc:creator>Kumar6</dc:creator>
    <dc:date>2020-07-17T03:51:41Z</dc:date>
    <item>
      <title>iteration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iteration/m-p/670047#M201089</link>
      <description>&lt;P&gt;By using the below code I am trying to create 2 records. First record should be "JG" and other has to be "VC", but I only get "JG" in 2 records.&lt;BR /&gt;Can you help me how to create this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data sub1;&lt;BR /&gt;subj = "201";&lt;BR /&gt;armcd = "JGVC";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%let k =1;&lt;/P&gt;&lt;P&gt;data sub2;&lt;BR /&gt;set sub1;&lt;BR /&gt;armlen = length(armcd);&lt;BR /&gt;do i = 1 to armlen/2;&lt;BR /&gt;length split_armcd $200;&lt;BR /&gt;split_armcd = substr(armcd,&amp;amp;k.,2);&lt;BR /&gt;split_armcdn = i;&lt;BR /&gt;%let k=%eval(&amp;amp;k + 2);&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Kumar.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2020 03:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iteration/m-p/670047#M201089</guid>
      <dc:creator>Kumar6</dc:creator>
      <dc:date>2020-07-17T03:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: iteration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iteration/m-p/670053#M201091</link>
      <description>&lt;P&gt;Macro statements and variables are resolved while the data step code is fetched for compilation, so the %eval will not have any effect on your data step code.&lt;/P&gt;
&lt;P&gt;Do this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sub2;
set sub1;
length split_armcd $2;
do i = 1 to length(armlen) by 2;
  split_armcd = substr(armcd,i,2);
  split_armcdn = i / 2;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested, posted from my tablet)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Simplified and tested code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sub2;
set sub1;
length split_armcd $2;
do split_armcdn = 1 to length(armcd) / 2;
  split_armcd = substr(armcd,split_armcdn * 2 - 1,2);
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Jul 2020 07:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iteration/m-p/670053#M201091</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-21T07:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: iteration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iteration/m-p/670055#M201093</link>
      <description>&lt;P&gt;Why are you using macro-variables? Both %let-statements are evaluated even before the data-step is compiled, so the second %let has no effect on the code of the data-step at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data sub2;
   set sub1;
   
   length split_armcd $200;

   k = 1;
   armlen=lengthn(armcd);

   do i=1 to armlen/2;
      split_armcd=substr(armcd, k, 2);
      split_armcdn=i;
      k = k + 2;
      output;
   end;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Jul 2020 04:54:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iteration/m-p/670055#M201093</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-07-17T04:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: iteration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iteration/m-p/670126#M201122</link>
      <description>&lt;P&gt;Thank You for your time.....&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2020 14:01:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iteration/m-p/670126#M201122</guid>
      <dc:creator>Kumar6</dc:creator>
      <dc:date>2020-07-17T14:01:45Z</dc:date>
    </item>
  </channel>
</rss>

