<?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: do loop coding in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/do-loop-coding/m-p/642164#M191545</link>
    <description>&lt;P&gt;Yes, you can - just define two arrays and use two loops, have a look at &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=p1cydk5fq0u4bfn1xfbjt7w1c7lu.htm&amp;amp;locale=en" target="_self"&gt;DO Statement: Iterative&lt;/A&gt; for details on how to implement the loops.&lt;/P&gt;</description>
    <pubDate>Thu, 23 Apr 2020 05:43:36 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2020-04-23T05:43:36Z</dc:date>
    <item>
      <title>do loop coding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-coding/m-p/642163#M191544</link>
      <description>&lt;P&gt;good day,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;can i write a do loop for below script so that i can easily repeat the script itself?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data part1v4;&lt;BR /&gt;set part1v3;&lt;BR /&gt;format percent percent10.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sum_checking=sum(checking1,checking2,checking3,checking4,checking5,checking6,checking7);&lt;BR /&gt;count_word=countw(CLEANED_BY_WORD);&lt;BR /&gt;percent=sum_checking/count_word;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if column7^="" then last_work=column7;&lt;BR /&gt;else if column6^="" and last_work="" then last_work=column6;&lt;BR /&gt;else if column5^="" and last_work="" then last_work=column5;&lt;BR /&gt;else if column4^="" and last_work="" then last_work=column4;&lt;BR /&gt;else if column3^="" and last_work="" then last_work=column3;&lt;BR /&gt;else if column2^="" and last_work="" then last_work=column2;&lt;BR /&gt;else if column1^="" and last_work="" then last_work=column1;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;if checking1="" then wrong_first_appear=1;&lt;BR /&gt;else if checking2="" then wrong_first_appear=2;&lt;BR /&gt;else if checking3="" then wrong_first_appear=3;&lt;BR /&gt;else if checking4="" then wrong_first_appear=4;&lt;BR /&gt;else if checking5="" then wrong_first_appear=5;&lt;BR /&gt;else if checking6="" then wrong_first_appear=6;&lt;BR /&gt;else if checking7="" then wrong_first_appear=7;&lt;/P&gt;
&lt;P&gt;clean_by_word2=lag(CLEANED_BY_WORD);&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;if percent=0.8 then modifed_name=clean_by_word2;&lt;BR /&gt;if percent=0.75 and wrong_first_appear=count_word and CLEANED_BY_WORD then modifed_name=clean_by_word2;&lt;/P&gt;
&lt;P&gt;drop clean_by_word2;&lt;BR /&gt;if modifed_name^="" then CLEANED_BY_WORD=modifed_name;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks in advance,&lt;/P&gt;
&lt;P&gt;Harry&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 05:29:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-coding/m-p/642163#M191544</guid>
      <dc:creator>harrylui</dc:creator>
      <dc:date>2020-04-23T05:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: do loop coding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-coding/m-p/642164#M191545</link>
      <description>&lt;P&gt;Yes, you can - just define two arrays and use two loops, have a look at &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=p1cydk5fq0u4bfn1xfbjt7w1c7lu.htm&amp;amp;locale=en" target="_self"&gt;DO Statement: Iterative&lt;/A&gt; for details on how to implement the loops.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 05:43:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-coding/m-p/642164#M191545</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-04-23T05:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: do loop coding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-coding/m-p/642172#M191547</link>
      <description>&lt;P&gt;you can try arrays as below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data part1v4;
set part1v3;
format percent percent10.;

sum_checking=sum(checking1,checking2,checking3,checking4,checking5,checking6,checking7);
count_word=countw(CLEANED_BY_WORD);
percent=sum_checking/count_word;

array vars1(7)$ column1-column7;
array vars2(7)$ checking1-checking7;

do i = 1 to 7 ;
if vars1(i)^="" then last_work=vars1(i);

if vars2(i)="" then wrong_first_appear=i;
end;
clean_by_word2=lag(CLEANED_BY_WORD);

if percent=0.8 then modifed_name=clean_by_word2;
if percent=0.75 and wrong_first_appear=count_word and CLEANED_BY_WORD then modifed_name=clean_by_word2;

drop clean_by_word2;
if modifed_name^="" then CLEANED_BY_WORD=modifed_name;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Apr 2020 07:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-coding/m-p/642172#M191547</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-04-23T07:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: do loop coding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-coding/m-p/642186#M191551</link>
      <description>&lt;P&gt;hi&lt;/P&gt;
&lt;P&gt;thanks for your help.&lt;/P&gt;
&lt;P&gt;here is my new modified code.&lt;/P&gt;
&lt;P&gt;can i repeat this&amp;nbsp;data part1v4 step for three to four times by do looping&lt;/P&gt;
&lt;P&gt;as you may notice, i will drop the new added array in this program last phrase and return this data into original form.&lt;/P&gt;
&lt;P&gt;i am working on some data cleansing step so my idea is to repeatedly run&amp;nbsp;&lt;/P&gt;
&lt;P&gt;part1v4 X4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data part1v4;&lt;BR /&gt;set part1v4;&lt;/P&gt;
&lt;P&gt;array column(7) $ 50;&lt;/P&gt;
&lt;P&gt;do i=1 to countw(CLEANED_BY_WORD);&lt;BR /&gt;column(i) = scan(CLEANED_BY_WORD,i," ");&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;BR /&gt;array lag_column(7) $ 50;&lt;BR /&gt;do i= 1 to 7;&lt;BR /&gt;lag_column(i)=lag(column(i));&lt;BR /&gt;end;&lt;BR /&gt;if lag_column1=column1 and column1 ^="" and lag_column1^="" then checking1 =1;&lt;BR /&gt;if lag_column2=column2 and column2 ^="" and lag_column2^="" then checking2 =1;&lt;BR /&gt;if lag_column3=column3 and column3 ^="" and lag_column3^="" then checking3 =1;&lt;BR /&gt;if lag_column4=column4 and column4 ^="" and lag_column4^="" then checking4 =1;&lt;BR /&gt;if lag_column5=column5 and column5 ^="" and lag_column5^="" then checking5 =1;&lt;BR /&gt;if lag_column6=column6 and column6 ^="" and lag_column6^="" then checking6 =1;&lt;BR /&gt;if lag_column7=column7 and column7 ^="" and lag_column7^="" then checking7 =1;&lt;BR /&gt;;&lt;BR /&gt;format percent percent10.;&lt;/P&gt;
&lt;P&gt;sum_checking=sum(checking1,checking2,checking3,checking4,checking5,checking6,checking7);&lt;BR /&gt;count_word=countw(CLEANED_BY_WORD);&lt;BR /&gt;percent=sum_checking/count_word;&lt;/P&gt;
&lt;P&gt;if checking1="" then wrong_first_appear=1;&lt;BR /&gt;else if checking2="" then wrong_first_appear=2;&lt;BR /&gt;else if checking3="" then wrong_first_appear=3;&lt;BR /&gt;else if checking4="" then wrong_first_appear=4;&lt;BR /&gt;else if checking5="" then wrong_first_appear=5;&lt;BR /&gt;else if checking6="" then wrong_first_appear=6;&lt;BR /&gt;else if checking7="" then wrong_first_appear=7;&lt;/P&gt;
&lt;P&gt;clean_by_word2=lag(CLEANED_BY_WORD);&lt;/P&gt;
&lt;P&gt;if percent=0.8 then modifed_name=clean_by_word2;&lt;BR /&gt;if percent=0.75 and wrong_first_appear=count_word and CLEANED_BY_WORD not in ("A AND A GEMS")then modifed_name=clean_by_word2;&lt;BR /&gt;if modifed_name^="" then CLEANED_BY_WORD=modifed_name;&lt;/P&gt;
&lt;P&gt;drop&lt;BR /&gt;column1 column2 column3 column4 column5 column6 column7&lt;BR /&gt;checking1 checking2 checking3 checking4 checking5 checking6 checking7&lt;BR /&gt;lag_column1 lag_column2 lag_column3 lag_column4 lag_column5 lag_column6 lag_column7&lt;BR /&gt;sum_checking count_word percent clean_by_word2 modifed_name wrong_first_appear last_work&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 08:32:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-coding/m-p/642186#M191551</guid>
      <dc:creator>harrylui</dc:creator>
      <dc:date>2020-04-23T08:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: do loop coding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-coding/m-p/642188#M191552</link>
      <description>It is always a good practice to use a different dataset name in set statement and create a new dataset with a new name.</description>
      <pubDate>Thu, 23 Apr 2020 08:52:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-coding/m-p/642188#M191552</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-04-23T08:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: do loop coding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-coding/m-p/642243#M191563</link>
      <description>&lt;P&gt;A sum of elements divided by the number of elements is a MEAN.&lt;/P&gt;
&lt;P&gt;So this code:&lt;/P&gt;
&lt;PRE&gt;sum_checking=sum(checking1,checking2,checking3,checking4,checking5,checking6,checking7);
count_word=countw(CLEANED_BY_WORD);
percent=sum_checking/count_word;&lt;/PRE&gt;
&lt;P&gt;Assuming that "cleaned_by_word" matches the number of checking values then perhaps could be replaced with&lt;/P&gt;
&lt;PRE&gt;percent_sum = mean(checking1, checking2, checking3, checking4,checking5, checking6, checking7);&lt;/PRE&gt;
&lt;P&gt;I am a bit leery of this code:&lt;/P&gt;
&lt;PRE&gt;if percent=0.8 then modifed_name=clean_by_word2;
if percent=0.75 &lt;/PRE&gt;
&lt;P&gt;because with 7 elements I would not expect to get 0.8 of 0.75 for any division by 7.&amp;nbsp; 7* 0.8 = 5.6, 7*0.75 =5.25.&lt;/P&gt;
&lt;P&gt;There are similar issues with most of the possible counts. I suspect that you maybe should be checking a range of values for percent but without any actual data and desired outcome this is a bit difficult to verify.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 14:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-coding/m-p/642243#M191563</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-23T14:23:19Z</dc:date>
    </item>
  </channel>
</rss>

