<?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: base in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277756#M55815</link>
    <description>&lt;P&gt;I always post a question as a last option after not finding any answer. I also learn new things from the forum. You guys are really great. Thanks.&lt;/P&gt;</description>
    <pubDate>Thu, 16 Jun 2016 03:57:29 GMT</pubDate>
    <dc:creator>knveraraju91</dc:creator>
    <dc:date>2016-06-16T03:57:29Z</dc:date>
    <item>
      <title>Finding values using a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277444#M55709</link>
      <description>&lt;P&gt;Dear sir,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am having little difficult in my code using array statement. I am using the following code. I am having trouble in concatenation part of my code. Please help where is wrong in my code.&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;data one;&lt;BR /&gt;input AESER $ AESDTH $ AESLIFE $ AESHOSP $ AESCONG $ AESDISAB $ AESMIE $ INFECDIS $;&lt;BR /&gt;datalines;&lt;BR /&gt;N N N N N N N N&lt;BR /&gt;Y N N N N N N N&lt;BR /&gt;Y Y N N N N N N&lt;BR /&gt;Y Y N N N N N N&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data two;&lt;BR /&gt;length aesern $20;&lt;BR /&gt;set one;&lt;BR /&gt;if AESER = 'N' THEN AESERN = 'No';&lt;BR /&gt;array AESP {7} $ AESDTH AESLIFE AESHOSP AESCONG AESDISAB AESMIE INFECDIS;&lt;BR /&gt;do i = 1 to 7;&lt;BR /&gt;if AESER = 'Y' and AESP (i) = 'N' then AESERN = 'Yes';&lt;BR /&gt;if AESER = 'Y' and AESP (i) = 'Y' then AESERN= 'Yes'||''||compress('('||i||')');;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OUTPUT:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;AESERN value for observations 2-4 is 'YES'. But I am expecting' YES &amp;nbsp;(1) ' for 3 and 4 observations. why the concatenation part not working.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 05:30:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277444#M55709</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2016-06-15T05:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277445#M55710</link>
      <description>&lt;P&gt;You changed the query by the time I came back to answer. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 04:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277445#M55710</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2016-06-15T04:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277451#M55712</link>
      <description>&lt;P&gt;You always execute the loop until I=7 and the values are N for I=7.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to keep the match for Y, you must exit the loop when you find it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data TWO;
  length AESERN $20;
  set ONE;
  array AESP {7} $ AESDTH -- INFECDIS;
  if AESER = 'N' then AESERN = 'No';
  else do I = 1 to 7;
    if AESP (I) = 'Y' then do;
      AESERN= cats('Yes(',I,')');
      leave;
    end;
    else AESERN = 'Yes';
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 05:07:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277451#M55712</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-06-15T05:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277453#M55713</link>
      <description>&lt;P&gt;You can also write this like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data TWO;
  length AESERN $20;
  set ONE;
  array AESP {7} $ AESDTH -- INFECDIS;
  FIND_Y = whichc('Y', of AESP[*]);
  AESERN = ifc( AESER = 'N' 
              , 'No'
              , 'Yes' || ifc(FIND_Y, cats('(',FIND_Y,')'), ''));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Jun 2016 05:15:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277453#M55713</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-06-15T05:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277454#M55714</link>
      <description>&lt;P&gt;Thank you. That helped me. But there is one issue that this code is not getting the right output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For observation 5, I suppose to get the out put like this&amp;nbsp;"Yes (1,6)".&amp;nbsp;&amp;nbsp;But I am getting &amp;nbsp;&lt;SPAN&gt;"Yes (1)". Please help in the code. Thank you&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data one;&lt;BR /&gt;input AESER $ AESDTH $ AESLIFE $ AESHOSP $ AESCONG $ AESDISAB $ AESMIE $ INFECDIS $;&lt;BR /&gt;datalines;&lt;BR /&gt;N N N N N N N N&lt;BR /&gt;Y N N N N N N N&lt;BR /&gt;Y Y N N N N N N&lt;BR /&gt;Y Y N N N N N N&lt;/P&gt;&lt;P&gt;Y Y Y N N N N N&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data two;&lt;BR /&gt;length aesern $20;&lt;BR /&gt;set one;&lt;BR /&gt;if AESER = 'N' THEN AESERN = 'No';&lt;BR /&gt;array AESP {7} $ AESDTH AESLIFE AESHOSP AESCONG AESDISAB AESMIE INFECDIS;&lt;BR /&gt;do i = 1 to 7;&lt;BR /&gt;if AESER = 'Y' and AESP (i) = 'N' then AESERN = 'Yes';&lt;BR /&gt;if AESER = 'Y' and AESP (i) = 'Y' then AESERN= 'Yes'||''||compress('('||i||')');;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OUTPUT:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;AESERN value for observations 2-4 is 'YES'. But I am expecting' YES &amp;nbsp;(1) ' for 3 and 4 observations. why the concatenation part not working.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 05:16:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277454#M55714</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2016-06-15T05:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277456#M55715</link>
      <description>&lt;P&gt;Why 1,6?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 05:19:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277456#M55715</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-06-15T05:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277460#M55718</link>
      <description>&lt;P&gt;Observation 5 has two 'Y' other than for AESER. One for AESDTH and another for AESLIFE. In array statement AESDTH =1 and AESLIFE=2. So, my output should be &lt;SPAN&gt;"Yes (1,2)"&lt;/SPAN&gt;&amp;nbsp;.I have to concatenate both values to YES. Thank you for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For observation 5, I suppose to get the out put like this "Yes (1,6)". But I am getting "Yes (1)". Please help in the code. Thank you&lt;BR /&gt;&lt;BR /&gt;data one;&lt;BR /&gt;input AESER $ AESDTH $ AESLIFE $ AESHOSP $ AESCONG $ AESDISAB $ AESMIE $ INFECDIS $;&lt;BR /&gt;datalines;&lt;BR /&gt;N N N N N N N N&lt;BR /&gt;Y N N N N N N N&lt;BR /&gt;Y Y N N N N N N&lt;BR /&gt;Y Y N N N N N N&lt;BR /&gt;Y Y Y N N N N N&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data two;&lt;BR /&gt;length aesern $20;&lt;BR /&gt;set one;&lt;BR /&gt;if AESER = 'N' THEN AESERN = 'No';&lt;BR /&gt;array AESP {7} $ AESDTH AESLIFE AESHOSP AESCONG AESDISAB AESMIE INFECDIS;&lt;BR /&gt;do i = 1 to 7;&lt;BR /&gt;if AESER = 'Y' and AESP (i) = 'N' then AESERN = 'Yes';&lt;BR /&gt;if AESER = 'Y' and AESP (i) = 'Y' then AESERN= 'Yes'||''||compress('('||i||')');;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;OUTPUT:&lt;BR /&gt;AESERN value for observations 2-4 is 'YES'. But I am expecting' YES (1) ' for 3 and 4 observations. why the concatenation part not working.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 05:34:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277460#M55718</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2016-06-15T05:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277461#M55719</link>
      <description>&lt;P&gt;Please do not copy all the text each time as your replies become mixed with your previous (erroneous in this case) replies.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data TWO;
  length AESERN $20;
  set one;
  array AESP {7} $ AESDTH -- INFECDIS;
  array POS  {7} $1 ;
  drop I POS:;
  AESERN =ifc( AESER = 'N' , 'No', 'Yes');
  if AESERN = 'Yes' and whichc('Y', of AESP[*]) then do;
    do I = 1 to 7;
      if AESP[I]='Y' then POS[I]=cat(I);  
    end;
    AESERN = cats(AESERN, '(', catx(',', of POS[*]), ')');
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Jun 2016 05:38:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277461#M55719</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-06-15T05:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277463#M55720</link>
      <description>&lt;P&gt;Trace your code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lets look at line 5 of your data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i=1 &amp;amp; second if statement is true so you set variable = Yes (1)&lt;/P&gt;
&lt;P&gt;i=2 &amp;amp; second if condition is true so you set variable = Yes (2)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At this point you've already overwritten your original variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You logic inside the loop isn't what you want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try looping through and creating a list of cases where you find your Y. Then check it against first condition and append the Yes portion and your list.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would recommend pseudocoding it for yourself first and then trying to program it. It's not a difficult problem but it's not trivial either and you'll learn more.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 05:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277463#M55720</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-15T05:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277464#M55721</link>
      <description>&lt;P&gt;Thank you so much&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 05:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277464#M55721</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2016-06-15T05:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277466#M55723</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/68272"&gt;@knveraraju91﻿&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ﻿&lt;/a&gt;&amp;nbsp;has provided the correct answer, not me.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 05:46:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277466#M55723</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-15T05:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277475#M55726</link>
      <description>&lt;P&gt;Cheers &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&amp;nbsp;. Life isn't fair is it?&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 06:04:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277475#M55726</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-06-15T06:04:50Z</dc:date>
    </item>
    <item>
      <title>Re: base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277489#M55730</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the help. I have one more thing I need help in the code if you can.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The out put produced as expected, but I need one more modifification.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With your code I am getting out for 3,4,5 observation is=&amp;nbsp;Yes(1) and&amp;nbsp;Yes(1,2). &amp;nbsp;But I need a gap between YES and the parenthesis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;eg: I need output ike this:&amp;nbsp;&lt;SPAN&gt;Yes (1) and&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Yes (1,2).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 06:38:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277489#M55730</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2016-06-15T06:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277698#M55785</link>
      <description>&lt;P&gt;Really?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;People here don't help you to do your job for you, but to show you so you can learn.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a trivial change when the final concatenation takes place. Please understand the few lines of code and change them accordingly.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:04:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277698#M55785</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-06-15T22:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277756#M55815</link>
      <description>&lt;P&gt;I always post a question as a last option after not finding any answer. I also learn new things from the forum. You guys are really great. Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 03:57:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-values-using-a-loop/m-p/277756#M55815</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2016-06-16T03:57:29Z</dc:date>
    </item>
  </channel>
</rss>

