<?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 looping error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-looping-error/m-p/34634#M6807</link>
    <description>A number of problems are in your code.&lt;BR /&gt;
&lt;BR /&gt;
1) your IF statement is before your SET therefore the IF statement is executed before the SET and will never happen.  How would SAS know what the value of status and drug_cde is? from what file? Also your logic to just bring in those records where status='1' and drug_cde=33  is way off on how SAS actually processes data.&lt;BR /&gt;
&lt;BR /&gt;
2) is drug_cde a character data in your input dataset?  The error message leads me to believe that&lt;BR /&gt;
&lt;BR /&gt;
3) since you only want to "bring in" records where status='1' and drug_cde=33 just put that in your where option in the SET statement.&lt;BR /&gt;
&lt;BR /&gt;
4) a good programming practice is not to put a %LET inside of a DATA STEP.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
See below .....&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%macro overall;&lt;BR /&gt;
&lt;BR /&gt;
%local status drug_cde1 ;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%let status = '1';&lt;BR /&gt;
%let drug_cde1 = 33;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data lIB.Drug33 (keep= DRUG_CDE1 S_P_NAME PROVIDER SRVC_PROV_NPI PRSC_PRV FROM_DTE BIRTH STATUS RECIP TENT_PAY SERV_FEE QTY_DISP);&lt;BR /&gt;
&lt;BR /&gt;
set  %do i = 1 %to 7;&lt;BR /&gt;
        p_claim.Inv06_2010_&amp;amp;i  (where=(status=&amp;amp;status and drug_cde1 =&amp;amp;drug_cde1  ))&lt;BR /&gt;
&lt;BR /&gt;
%end;&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
%overall</description>
    <pubDate>Mon, 21 Mar 2011 20:21:39 GMT</pubDate>
    <dc:creator>darrylovia</dc:creator>
    <dc:date>2011-03-21T20:21:39Z</dc:date>
    <item>
      <title>Macro looping error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-looping-error/m-p/34632#M6805</link>
      <description>I want the following macro to loop through a series of invoices INV06 and choose them.&lt;BR /&gt;
&lt;BR /&gt;
%macro overall;&lt;BR /&gt;
data lIB.Drug33 (keep= DRUG_CDE1 S_P_NAME PROVIDER SRVC_PROV_NPI PRSC_PRV FROM_DTE BIRTH  STATUS RECIP TENT_PAY SERV_FEE QTY_DISP);&lt;BR /&gt;
	%let status = '1';&lt;BR /&gt;
	%let drug_cde1 = 33;&lt;BR /&gt;
		if status = &amp;amp;status&lt;BR /&gt;
			and drug_cde1 =&amp;amp;drug_cde1 then&lt;BR /&gt;
	  set&lt;BR /&gt;
  %do i = 1 %to 2; /*where 1 is the first number and 7 is the last*/&lt;BR /&gt;
		&lt;BR /&gt;
    p_claim.Inv06_2010_&amp;amp;i &lt;BR /&gt;
		&lt;BR /&gt;
  %end;&lt;BR /&gt;
  ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
%overall; &lt;BR /&gt;
&lt;BR /&gt;
I am trying to limit the pull to those with a status of '1' and a drug_cde of 33.  However when I run the program I get the following errors;&lt;BR /&gt;
ERROR: Variable drug_cde1 has been defined as both character and numeric.&lt;BR /&gt;
ERROR: File WORK.IF.DATA does not exist.&lt;BR /&gt;
ERROR: File WORK.STATUS.DATA does not exist.&lt;BR /&gt;
ERROR: The value 1 is not a valid SAS name.&lt;BR /&gt;
NOTE: Line generated by the macro variable "I".&lt;BR /&gt;
1            p_claim.Inv06_2010_2&lt;BR /&gt;
             --------------------&lt;BR /&gt;
             557&lt;BR /&gt;
ERROR: DATA STEP Component Object failure.  Aborted during the COMPILATION phase.&lt;BR /&gt;
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, -, :,&lt;BR /&gt;
              ;, END, INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.&lt;BR /&gt;
&lt;BR /&gt;
ERROR 200-322: The symbol is not recognized and will be ignored.&lt;BR /&gt;
&lt;BR /&gt;
ERROR 557-185: Variable p_claim is not an object.</description>
      <pubDate>Mon, 21 Mar 2011 19:01:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-looping-error/m-p/34632#M6805</guid>
      <dc:creator>omega1983</dc:creator>
      <dc:date>2011-03-21T19:01:36Z</dc:date>
    </item>
    <item>
      <title>Re: Macro looping error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-looping-error/m-p/34633#M6806</link>
      <description>Hello Omega1983,&lt;BR /&gt;
&lt;BR /&gt;
I emulated your code with artificial data and it works fine. It means the problem lies in data. Please submit a sample of you data.&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Mon, 21 Mar 2011 20:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-looping-error/m-p/34633#M6806</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-03-21T20:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macro looping error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-looping-error/m-p/34634#M6807</link>
      <description>A number of problems are in your code.&lt;BR /&gt;
&lt;BR /&gt;
1) your IF statement is before your SET therefore the IF statement is executed before the SET and will never happen.  How would SAS know what the value of status and drug_cde is? from what file? Also your logic to just bring in those records where status='1' and drug_cde=33  is way off on how SAS actually processes data.&lt;BR /&gt;
&lt;BR /&gt;
2) is drug_cde a character data in your input dataset?  The error message leads me to believe that&lt;BR /&gt;
&lt;BR /&gt;
3) since you only want to "bring in" records where status='1' and drug_cde=33 just put that in your where option in the SET statement.&lt;BR /&gt;
&lt;BR /&gt;
4) a good programming practice is not to put a %LET inside of a DATA STEP.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
See below .....&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%macro overall;&lt;BR /&gt;
&lt;BR /&gt;
%local status drug_cde1 ;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%let status = '1';&lt;BR /&gt;
%let drug_cde1 = 33;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data lIB.Drug33 (keep= DRUG_CDE1 S_P_NAME PROVIDER SRVC_PROV_NPI PRSC_PRV FROM_DTE BIRTH STATUS RECIP TENT_PAY SERV_FEE QTY_DISP);&lt;BR /&gt;
&lt;BR /&gt;
set  %do i = 1 %to 7;&lt;BR /&gt;
        p_claim.Inv06_2010_&amp;amp;i  (where=(status=&amp;amp;status and drug_cde1 =&amp;amp;drug_cde1  ))&lt;BR /&gt;
&lt;BR /&gt;
%end;&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
%overall</description>
      <pubDate>Mon, 21 Mar 2011 20:21:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-looping-error/m-p/34634#M6807</guid>
      <dc:creator>darrylovia</dc:creator>
      <dc:date>2011-03-21T20:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: Macro looping error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-looping-error/m-p/34635#M6808</link>
      <description>Hello Darrylovia,&lt;BR /&gt;
&lt;BR /&gt;
I agree with your ponts 2 - 4 but not 1. I've tested it works.&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Mon, 21 Mar 2011 20:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-looping-error/m-p/34635#M6808</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-03-21T20:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Macro looping error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-looping-error/m-p/34636#M6809</link>
      <description>SPR&lt;BR /&gt;
My bust you are correct&lt;BR /&gt;
&lt;BR /&gt;
For those in the forum see the below code as a demostration&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data s1(drop=s2) s2(drop=s1);&lt;BR /&gt;
  set sashelp.shoes;&lt;BR /&gt;
&lt;BR /&gt;
  inS1=1;&lt;BR /&gt;
  inS2=1;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%macro overall;&lt;BR /&gt;
&lt;BR /&gt;
data one;&lt;BR /&gt;
&lt;BR /&gt;
  %let Region='Africa';&lt;BR /&gt;
&lt;BR /&gt;
  if Region=&amp;amp;region then &lt;BR /&gt;
    set %do i=1 %to 2;&lt;BR /&gt;
	      s&amp;amp;i&lt;BR /&gt;
        %end;&lt;BR /&gt;
		;&lt;BR /&gt;
run;&lt;BR /&gt;
%mend overall;&lt;BR /&gt;
%overall;</description>
      <pubDate>Wed, 23 Mar 2011 17:10:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-looping-error/m-p/34636#M6809</guid>
      <dc:creator>darrylovia</dc:creator>
      <dc:date>2011-03-23T17:10:02Z</dc:date>
    </item>
  </channel>
</rss>

