<?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: Is there a Do-Loop solution for this? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-Do-Loop-solution-for-this/m-p/451089#M283790</link>
    <description>&lt;PRE&gt;data work.trans2;
  set work.trans_co;
  array ssn{52};
  do i=1 to 52;
    if ssn{i} ne "" and ssn{i} ne prov_ssn then del="Y";
  end;
run;&lt;/PRE&gt;&lt;P&gt;Does exactly what I need it to thank you!! I've only done this with basic calculations so this was very helpful.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Apr 2018 13:04:29 GMT</pubDate>
    <dc:creator>ErinRoberts</dc:creator>
    <dc:date>2018-04-04T13:04:29Z</dc:date>
    <item>
      <title>Is there a Do-Loop solution for this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-Do-Loop-solution-for-this/m-p/451055#M283785</link>
      <description>&lt;P&gt;I have some code I think could be made simpler using a do-loop but I'm not sure quite how to make it work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA WORK.TRANS2;&lt;BR /&gt;SET WORK.TRANS_co;&lt;BR /&gt;IF PROV_SSN NE SSN1 THEN DEL='Y';&lt;BR /&gt;ELSE IF SSN2 NE '' AND PROV_SSN NE SSN2 THEN DEL='Y';&lt;BR /&gt;ELSE IF SSN3 NE '' AND PROV_SSN NE SSN3 THEN DEL='Y';&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ELSE IF SSN52 NE '' AND PROV_SSN NE SSN52 THEN DEL='Y';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;RUN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Basically, I have 52 character variables I'm looking for differences between and if there are any differences, I want to assign&amp;nbsp;DEL='Y'.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any suggestions?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 12:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-Do-Loop-solution-for-this/m-p/451055#M283785</guid>
      <dc:creator>ErinRoberts</dc:creator>
      <dc:date>2018-04-04T12:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a Do-Loop solution for this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-Do-Loop-solution-for-this/m-p/451060#M283786</link>
      <description>&lt;P&gt;First step isn't to simplify.&amp;nbsp; First step is to produce working code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Right now, DEL will always be "Y".&amp;nbsp; If the first statement doesn't set DEL to "Y", the second one will (ignoring missing values).&amp;nbsp; After all, your variable won't equal SSN1 and SSN2 at the same time.&amp;nbsp; So when do you want DEL to be "Y"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's possible that this matches your intention:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;del='Y';&lt;/P&gt;
&lt;P&gt;array ssn {52};&lt;/P&gt;
&lt;P&gt;do k=1 to 52 until (del='N');&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if prov_ssn=ssn{k} then del='N';&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 12:38:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-Do-Loop-solution-for-this/m-p/451060#M283786</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-04T12:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a Do-Loop solution for this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-Do-Loop-solution-for-this/m-p/451062#M283787</link>
      <description>&lt;P&gt;This could be done via a macro %DO loop, but then to execute the entire data step, you would have to embed the data step inside a macro (because you can't have %DO in open code). So, something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I repeat&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis;
    data work.trans2;
         set work.trans_co;
         %do i=1 %to 52;
             %if &amp;amp;i&amp;gt;1 %then else if ssn&amp;amp;i ne ' ' and prov_ssn ne ssn&amp;amp;i then del='Y'%str(;);
             %else if prov_ssn ne snn&amp;amp;i then del='Y'%str(;);
         %end;
     run;
%mend;
%dothis&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Apr 2018 12:36:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-Do-Loop-solution-for-this/m-p/451062#M283787</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-04-04T12:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a Do-Loop solution for this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-Do-Loop-solution-for-this/m-p/451065#M283788</link>
      <description>&lt;P&gt;Actually, scrub that you can use whichc() function:&lt;/P&gt;
&lt;PRE&gt;data work.trans2;
  set work.trans2;
  if whichc(prov_ssn,of ssn:) then del="Y";
run;&lt;/PRE&gt;
&lt;P&gt;Note!! Not tested !!&amp;nbsp; Provide test data for tested code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you need is an array;&lt;/P&gt;
&lt;PRE&gt;data work.trans2;
  set work.trans2;
  array ssn{52};
  do over ssn;
    if ssn ne "" and ssn ne prov_ssn then del="Y";
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Note I use the code window (its the {i} above post) and not code all in uppercase.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, the over is a bit outdated now so to write with an indexer:&lt;/P&gt;
&lt;PRE&gt;data work.trans2;
  set work.trans2;
  array ssn{52};
  do i=1 to 52;
    if ssn{i} ne "" and ssn{i} ne prov_ssn then del="Y";
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Note that I assume (per your text) there are 52 ssnX variables all with a numeric suffix going 1, 2, 3 etc.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 12:44:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-Do-Loop-solution-for-this/m-p/451065#M283788</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-04-04T12:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a Do-Loop solution for this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-Do-Loop-solution-for-this/m-p/451081#M283789</link>
      <description>&lt;P&gt;Right now the code as I have it written works fine, it's just not user friendly if I have to add or remove variables.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 12:58:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-Do-Loop-solution-for-this/m-p/451081#M283789</guid>
      <dc:creator>ErinRoberts</dc:creator>
      <dc:date>2018-04-04T12:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a Do-Loop solution for this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-Do-Loop-solution-for-this/m-p/451089#M283790</link>
      <description>&lt;PRE&gt;data work.trans2;
  set work.trans_co;
  array ssn{52};
  do i=1 to 52;
    if ssn{i} ne "" and ssn{i} ne prov_ssn then del="Y";
  end;
run;&lt;/PRE&gt;&lt;P&gt;Does exactly what I need it to thank you!! I've only done this with basic calculations so this was very helpful.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 13:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-Do-Loop-solution-for-this/m-p/451089#M283790</guid>
      <dc:creator>ErinRoberts</dc:creator>
      <dc:date>2018-04-04T13:04:29Z</dc:date>
    </item>
  </channel>
</rss>

