<?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: Creating an incremented variable in a do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507869#M136340</link>
    <description>&lt;P&gt;I am using a variable that holds the string, and I won't know how many array elements I need so I am not sure how I can get this to work.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 26 Oct 2018 19:25:27 GMT</pubDate>
    <dc:creator>amyk</dc:creator>
    <dc:date>2018-10-26T19:25:27Z</dc:date>
    <item>
      <title>Creating an incremented variable in a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507861#M136336</link>
      <description>&lt;P&gt;I am having a difficult time finding a way to loop through a string a long string with no delimiters&amp;nbsp;and having a variable with every 5 positions in the string in its own column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;say I have a string the is 'D78fd87fda8787fads0f7df87fa87f9d8fa79d8f' I would need to break off ever 5 character in its own column&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have&amp;nbsp; created a loop which I end up with the last 5 poistion in a column I am trying to figure out how I can increment the Var every time it loops through to get all the data:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data temp;&lt;BR /&gt;set temp;&lt;BR /&gt;i = 1;&lt;BR /&gt;J = 1;&lt;/P&gt;&lt;P&gt;do i = 1 to &amp;amp;maxnum;&lt;BR /&gt;vars = substr(attrib_list, J, 5) ;&lt;BR /&gt;J= J+5;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 19:09:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507861#M136336</guid>
      <dc:creator>amyk</dc:creator>
      <dc:date>2018-10-26T19:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an incremented variable in a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507865#M136337</link>
      <description>&lt;P&gt;Are you after something like the results that the following code produces?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data want;
 str= 'D78fd87fda8787fads0f7df87fa87f9d8fa79d8f';
 array astr [8] $ 5  ; 
 call pokelong (str , addr (astr[1]) ,vlength(str)) ;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 19:23:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507865#M136337</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-26T19:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an incremented variable in a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507866#M136338</link>
      <description>You can increment in increments of 5 using a BY within the loop. &lt;BR /&gt;&lt;BR /&gt;do i=1 to &amp;amp;maxnum by 5;&lt;BR /&gt;vars = substr(attrib_list, i, 5);&lt;BR /&gt;output; *write out as a record;&lt;BR /&gt;end;</description>
      <pubDate>Fri, 26 Oct 2018 19:18:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507866#M136338</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-26T19:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an incremented variable in a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507869#M136340</link>
      <description>&lt;P&gt;I am using a variable that holds the string, and I won't know how many array elements I need so I am not sure how I can get this to work.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 19:25:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507869#M136340</guid>
      <dc:creator>amyk</dc:creator>
      <dc:date>2018-10-26T19:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an incremented variable in a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507870#M136341</link>
      <description>&lt;P&gt;I'm trying to create the var incrementing everytime a loop passes through and not incrementing the loop&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 19:26:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507870#M136341</guid>
      <dc:creator>amyk</dc:creator>
      <dc:date>2018-10-26T19:26:27Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an incremented variable in a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507872#M136343</link>
      <description>&lt;P&gt;None of that matters. All you need is to ensure that it's always an length that's a multiple of 5.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*create fake sample data;
data have;
infile cards truncover;
input myVar $255.;
cards;
D78fd87fda8787fads0f7df87fa87f9d8fa79d8f
Fr34327fda878884ds0f7df87fa8734332a79d8g
;;;;
run;


data want; 
set have;
Obs = _n_; *record number to know which go together;
len = length(myVar); *legnth of variable to loop only as needed;

do i=1 to len by 5; *loop;
    value = substr(myVar, i, 5); * extract string of size 5 each time;
    output; *output;
end;
run;

*wide format;
proc transpose data=want out=wide prefix=VAR;
by Obs;
var value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/242815"&gt;@amyk&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm trying to create the var incrementing everytime a loop passes through and not incrementing the loop&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 19:31:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507872#M136343</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-26T19:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an incremented variable in a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507877#M136346</link>
      <description>&lt;P&gt;Do string length vary every row? or is it consistent? if it is we can get the array elements at compile time. Nevertheless&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;has&amp;nbsp; given a solution that many should understand.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even the two pass solution&lt;/P&gt;
&lt;P&gt;1. loop&lt;/P&gt;
&lt;P&gt;2. transpose&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;will result in some vars having missing values should your string length vary.&amp;nbsp; So should I make a array subscript to (vlength/5) , APP's will be super robust.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 19:46:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507877#M136346</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-26T19:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an incremented variable in a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507880#M136347</link>
      <description>&lt;P&gt;This worked perfectly. Thank you so so much &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 19:56:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507880#M136347</guid>
      <dc:creator>amyk</dc:creator>
      <dc:date>2018-10-26T19:56:55Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an incremented variable in a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507882#M136348</link>
      <description>&lt;P&gt;Thank you for your help. The help I received from&amp;nbsp;&lt;SPAN&gt;Reeza was exactly what I was looking for.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 20:00:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507882#M136348</guid>
      <dc:creator>amyk</dc:creator>
      <dc:date>2018-10-26T20:00:28Z</dc:date>
    </item>
  </channel>
</rss>

