<?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: Macro Do Loops not working in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Do-Loops-not-working/m-p/322097#M71227</link>
    <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for late reply. I changed my code structure according to your advices and now it is working. I appreciate your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro success();
%let nitems = %sysfunc(countw(&amp;amp;var_list));
%let counter = %sysevalf(&amp;amp;nitems);
data new;
set old;
	%do i=1 %to &amp;amp;counter;
		%let var_used = %scan(&amp;amp;var_list,&amp;amp;i,'|');
		%if '&amp;amp;var_used.' ne  'VAR1' AND '&amp;amp;var_used.' ne 'VAR2' AND '&amp;amp;var_used.' ne 'VAR3' %then %do;	
			if &amp;amp;var_used gt 0.01 then flag_&amp;amp;var_used. = 'successful';
			else flag_&amp;amp;var_used. = 'unsuccesful'; 
		%end;
	%end;
run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 03 Jan 2017 10:41:42 GMT</pubDate>
    <dc:creator>fuatengin</dc:creator>
    <dc:date>2017-01-03T10:41:42Z</dc:date>
    <item>
      <title>Macro Do Loops not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Do-Loops-not-working/m-p/321731#M71100</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to distinguish some variables whether they are succesful or not. To do this I wrote the below macro but it does not work.&lt;/P&gt;&lt;P&gt;flag_&amp;amp;var_used. is not accepted as a variable name in SAS. I also do not get any result neither. I am stuck in this macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Help appreciated,&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;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro success();
%let nitems = %sysfunc(countw(&amp;amp;var_list));
%do i=1 %to &amp;amp;nitems;
%let var_used = %scan((&amp;amp;var_list),&amp;amp;i,'|');
	%if (&amp;amp;var_used ne  'VAR1' or &amp;amp;var_used ne 'VAR2' or &amp;amp;var_used ne 'VAR3') %then %do;
		data new_&amp;amp;i.;
		set old;	
			if &amp;amp;var_used gt 0.01 then flag_&amp;amp;var_used. = 'succesful';
			else flag_&amp;amp;var_used. = 'unsuccessful'; 
		run;
	%end;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Dec 2016 12:46:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Do-Loops-not-working/m-p/321731#M71100</guid>
      <dc:creator>fuatengin</dc:creator>
      <dc:date>2016-12-30T12:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Do Loops not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Do-Loops-not-working/m-p/321733#M71102</link>
      <description>&lt;P&gt;&amp;nbsp;your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;var_used ne  'VAR1' or &amp;amp;var_used ne 'VAR2' or &amp;amp;var_used ne 'VAR3'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;- macro variables are characters, so quotes are extra&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;- &amp;nbsp;if &amp;amp;var_used = VAR1 then it is ne VAR2. Your condition is always TRUE;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;change and try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;var_used ne  VAR1 &lt;STRONG&gt;and&lt;/STRONG&gt; &amp;amp;var_used ne VAR2 &lt;STRONG&gt;and&lt;/STRONG&gt; &amp;amp;var_used ne VAR3&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please post your log in case of error meesages.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Dec 2016 13:02:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Do-Loops-not-working/m-p/321733#M71102</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-12-30T13:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Do Loops not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Do-Loops-not-working/m-p/321748#M71107</link>
      <description>&lt;P&gt;In addition to removing the extra quotes, you need to remove the extra parentheses. &amp;nbsp;This is the first parameter to %SCAN:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(&amp;amp;var_list)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The parentheses are part of the text that %SCAN examines. &amp;nbsp;The first word in the list contains a left-hand parenthesis, and the last word contains a right-hand parenthesis.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A smaller issue ... the length of the flag_ variable should be set ahead of time. &amp;nbsp;Otherwise you will lose the "ul" from the end of "unsuccessful".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you might want to consider whether you could do this in one DATA step, rather than using a separate DATA step for each variable. If you want to go that route, it would be easier to create &amp;amp;VAR_LIST with blanks instead of pipes as the separators. &amp;nbsp;That would support this type of statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array vars {*} &amp;amp;var_list;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Dec 2016 15:33:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Do-Loops-not-working/m-p/321748#M71107</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-30T15:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Do Loops not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Do-Loops-not-working/m-p/321753#M71109</link>
      <description>&lt;P&gt;Is there a specific reason you are going through the same data set and creating multiple data sets instead of one pass that could create all of the variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also suggest that instead of creating a text variable that you might consider&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token operator"&gt;&amp;nbsp;= (&amp;amp;&lt;/SPAN&gt;var_used &lt;SPAN class="token operator"&gt;gt&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0.01);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token number"&gt;This will create a numeric coded variable with 1 for true (or successful or yes or what have you) and 0 for false/unsuccesful/no.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token number"&gt;Then you can Sum the &lt;SPAN class="token operator"&gt;flag_&amp;amp;var_used to get a count of successful and a mean would be the percentage succesful&amp;nbsp;in decimal form. Which may make some forms of reporting easier to write.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Dec 2016 16:28:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Do-Loops-not-working/m-p/321753#M71109</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-30T16:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Do Loops not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Do-Loops-not-working/m-p/322097#M71227</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for late reply. I changed my code structure according to your advices and now it is working. I appreciate your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro success();
%let nitems = %sysfunc(countw(&amp;amp;var_list));
%let counter = %sysevalf(&amp;amp;nitems);
data new;
set old;
	%do i=1 %to &amp;amp;counter;
		%let var_used = %scan(&amp;amp;var_list,&amp;amp;i,'|');
		%if '&amp;amp;var_used.' ne  'VAR1' AND '&amp;amp;var_used.' ne 'VAR2' AND '&amp;amp;var_used.' ne 'VAR3' %then %do;	
			if &amp;amp;var_used gt 0.01 then flag_&amp;amp;var_used. = 'successful';
			else flag_&amp;amp;var_used. = 'unsuccesful'; 
		%end;
	%end;
run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Jan 2017 10:41:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Do-Loops-not-working/m-p/322097#M71227</guid>
      <dc:creator>fuatengin</dc:creator>
      <dc:date>2017-01-03T10:41:42Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Do Loops not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Do-Loops-not-working/m-p/322098#M71228</link>
      <description>&lt;P&gt;Hello, Thank you for your post. I changed or's with and's. in my code.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2017 10:43:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Do-Loops-not-working/m-p/322098#M71228</guid>
      <dc:creator>fuatengin</dc:creator>
      <dc:date>2017-01-03T10:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Do Loops not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Do-Loops-not-working/m-p/322099#M71229</link>
      <description>&lt;P&gt;Hello ballardw, No I do not have any specific reason to create multiple datasets. That's why I changed my code. Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2017 10:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Do-Loops-not-working/m-p/322099#M71229</guid>
      <dc:creator>fuatengin</dc:creator>
      <dc:date>2017-01-03T10:47:12Z</dc:date>
    </item>
  </channel>
</rss>

