<?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: Running a Loop in Query Builder in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-a-Loop-in-Query-Builder/m-p/438616#M28325</link>
    <description>&lt;P&gt;Hi Paul,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Original solution to pad zeros to a character variable is here &lt;A href="https://communities.sas.com/t5/SAS-Procedures/how-to-pad-character-variable-with-leading-zeroes/td-p/40486" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/how-to-pad-character-variable-with-leading-zeroes/td-p/40486&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In EG query builder follow below steps&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; Query Builder&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; Add your input variables&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; Add a new computed column&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; Advanced Expression&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;nbsp;(repeat('0',8-length(COLUMNTOPAD0)-1)||&lt;SPAN&gt;COLUMNTOPAD0&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;and follow through to run the query&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;Selva&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Feb 2018 12:22:33 GMT</pubDate>
    <dc:creator>Selvaraj</dc:creator>
    <dc:date>2018-02-20T12:22:33Z</dc:date>
    <item>
      <title>Running a Loop in Query Builder</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-a-Loop-in-Query-Builder/m-p/438612#M28324</link>
      <description>&lt;P&gt;THis might be a daft question, but I've not needed to do this before and I'm struggling to find a guide or syntax anywhere.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can I run a loop in query builder?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm validating a column of reference numbers, I have one source where each reference has 8 characters, often with leading zeros.&amp;nbsp; I have a second data source wit the same references where the leading zeros have been stripped.&amp;nbsp; As a result I can't match the data properly, and I'd like to add the leading zeros back to the strings.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I basically want a loop that looks at the length of the string, if it's less than 8 then it concatenates a zero with the string, then loops through again.&amp;nbsp; Once the string is 8 characters long, end the loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this possible, is there a better way to do it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Paul.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2018 11:57:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-a-Loop-in-Query-Builder/m-p/438612#M28324</guid>
      <dc:creator>paulrockliffe</dc:creator>
      <dc:date>2018-02-20T11:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: Running a Loop in Query Builder</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-a-Loop-in-Query-Builder/m-p/438616#M28325</link>
      <description>&lt;P&gt;Hi Paul,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Original solution to pad zeros to a character variable is here &lt;A href="https://communities.sas.com/t5/SAS-Procedures/how-to-pad-character-variable-with-leading-zeroes/td-p/40486" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/how-to-pad-character-variable-with-leading-zeroes/td-p/40486&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In EG query builder follow below steps&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; Query Builder&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; Add your input variables&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; Add a new computed column&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; Advanced Expression&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;nbsp;(repeat('0',8-length(COLUMNTOPAD0)-1)||&lt;SPAN&gt;COLUMNTOPAD0&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;and follow through to run the query&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;Selva&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2018 12:22:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-a-Loop-in-Query-Builder/m-p/438616#M28325</guid>
      <dc:creator>Selvaraj</dc:creator>
      <dc:date>2018-02-20T12:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: Running a Loop in Query Builder</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-a-Loop-in-Query-Builder/m-p/438617#M28326</link>
      <description>&lt;P&gt;Thanks that looks like it'll sort me out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd still like to know if it's possible to use the equivalent of a Do Loop within Query Builder as it might be useful in the future, if anyone knows the answer to that?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2018 12:27:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-a-Loop-in-Query-Builder/m-p/438617#M28326</guid>
      <dc:creator>paulrockliffe</dc:creator>
      <dc:date>2018-02-20T12:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Running a Loop in Query Builder</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-a-Loop-in-Query-Builder/m-p/438626#M28327</link>
      <description>&lt;P&gt;You can use the z format to pad numbers out with zeros.&lt;/P&gt;
&lt;PRE&gt;data have;
  a=3456;
  b=put(a,z8.);
run;&lt;/PRE&gt;
&lt;P&gt;You will see b is:&lt;/P&gt;
&lt;P&gt;00003456&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use this technique in a merge (join in SQL) as well, so - and I don't use builders so you would need to adapt to your software:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table want as
  select *
  from   have 
  where id not in (select distinct(put(id,z8.)) from codelist);
quit;&lt;/PRE&gt;
&lt;P&gt;(Note no test data or anything to work with so just run up a simple example).&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2018 12:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-a-Loop-in-Query-Builder/m-p/438626#M28327</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-20T12:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: Running a Loop in Query Builder</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-a-Loop-in-Query-Builder/m-p/438627#M28328</link>
      <description>&lt;P&gt;No, do loops do not work in Query builder - this is an SQL builder software, and SQL does not have the concept of a do loop, it is a selection of data based on logical criteria.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2018 12:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-a-Loop-in-Query-Builder/m-p/438627#M28328</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-20T12:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Running a Loop in Query Builder</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-a-Loop-in-Query-Builder/m-p/438716#M28339</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/110699"&gt;@paulrockliffe&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks that looks like it'll sort me out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd still like to know if it's possible to use the equivalent of a Do Loop within Query Builder as it might be useful in the future, if anyone knows the answer to that?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not within the GUI tools for sure. You could with a macro language, but it's not an appropriate for this question anyways. An example would be if you had say 100 cols that you need to loop a calculation over. It's usually easier to switch to a data step at that point.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the value is also a number you can convert it to a numeric and then back to a character using Z8 format to ensure the leading zeroes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put(input(my_var, 8.), z8.) as padded_variable
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;GUI tools get you about 75% of the way. You can get another 15% via some workarounds and multiple steps in a GUI that would be a single data step. And the last 10% requires pure code. In my experience that's true of most GUI analytical tools in the market today.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2018 16:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-a-Loop-in-Query-Builder/m-p/438716#M28339</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-20T16:53:46Z</dc:date>
    </item>
  </channel>
</rss>

