<?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 Error? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865489#M341796</link>
    <description>&lt;P&gt;From now on, please include the log by clicking on the &amp;lt;/&amp;gt; icon and pasting the log into the window that appears.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1663012019648.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75161i0E71B1489A6C9839/image-size/large?v=v2&amp;amp;px=999" role="button" title="PaigeMiller_0-1663012019648.png" alt="PaigeMiller_0-1663012019648.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This preserves the formatting of the log. Like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ERROR: The following columns were not found in the contributing tables: c_los.&lt;/PRE&gt;
&lt;P&gt;There is no variable named c_los in the SAS data set being used by PROC SQL. So you get the error. (And by the way, this error has nothing to do with macros — because your code does not contain macros, it contains macro variables — but this error is a coding error, not a macro error). The fix is as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where scrdate ^=. and inptadmitdt ^=. and inptdischargedt ^=. and inptadmitdt ne '09SEP9999'd and inptdischargedt ne '09SEP9999'd
	   and (calculated c_los&amp;lt;0 or calculated c_los&amp;gt;100)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The word calculated tells PROC SQL to use a variable previously calculated by PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Mar 2023 17:03:35 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-03-21T17:03:35Z</dc:date>
    <item>
      <title>Macro Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865474#M341789</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following code.&amp;nbsp; There is an error on the log window when running.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let i=(&amp;amp;rr + 1);
%let rr=%eval(&amp;amp;i);

proc sql;
create table inpcr&amp;amp;rr as
 select studysite,caseid,scrdate,inptadmitdt,inptdischargedt, intck('day',inptadmitdt, inptdischargedt) as c_los
 from ds2INP
 where scrdate ^=. and inptadmitdt ^=. and inptdischargedt ^=. and inptadmitdt ne '09SEP9999'd and inptdischargedt ne '09SEP9999'd
	   and (c_los&amp;lt;0 or c_los&amp;gt;100)
order by studysite,caseid;

%let inp_&amp;amp;rr.a=%str(Missing length of stay or extreme value [negative or &amp;gt;100 days]);

ods proclabel "Check &amp;amp;rr:&amp;amp;&amp;amp;&amp;amp;inp_&amp;amp;rr.a";

data inpcr&amp;amp;rr;
set inpcr&amp;amp;rr;
*if inptdischargedt='09SEP9999'd then delete;
var1="scrdate="||trim(left(put(scrdate,mmddyy10.)))
||', '||"inptadmitdt="||trim(left(put(inptadmitdt,mmddyy10.)))
||', '||"inptdischargedt="||trim(left(put(inptdischargedt,mmddyy10.))) 
||', '||"c_los="||trim(left(put(c_los,3.)));
format studysite studysite.;
/* site confirmed with checks */
if caseid in ('E1'.'K8','R0','ER') then delete;
run;

%createINP;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;LI-SPOILER&gt;
&lt;P&gt;MPRINT(ARIINPCHART): ;&lt;BR /&gt;MPRINT(ARIINPCHART): proc sql;&lt;BR /&gt;MPRINT(ARIINPCHART): create table inpcr26 as select&lt;BR /&gt;studysite,caseid,scrdate,inptadmitdt,inptdischargedt, intck('day',inptadmitdt, inptdischargedt) as&lt;BR /&gt;c_los from ds2INP where scrdate ^=. and inptadmitdt ^=. and inptdischargedt ^=. and inptadmitdt ne&lt;BR /&gt;'09SEP9999'd and inptdischargedt ne '09SEP9999'd and (c_los&amp;lt;0 or c_los&amp;gt;100) order by studysite,caseid;&lt;BR /&gt;ERROR: The following columns were not found in the contributing tables: c_los.&lt;BR /&gt;MPRINT(ARIINPCHART): ods proclabel "Check 26:Missing length of stay or extreme value [negative or&lt;BR /&gt;&amp;gt;100 days]";&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;MPRINT(ARIINPCHART): data inpcr26;&lt;BR /&gt;MPRINT(ARIINPCHART): set inpcr26;&lt;BR /&gt;MPRINT(ARIINPCHART): *if inptdischargedt='09SEP9999'd then delete;&lt;BR /&gt;MPRINT(ARIINPCHART): var1="scrdate="||trim(left(put(scrdate,mmddyy10.))) ||',&lt;BR /&gt;'||"inptadmitdt="||trim(left(put(inptadmitdt,mmddyy10.))) ||',&lt;BR /&gt;'||"inptdischargedt="||trim(left(put(inptdischargedt,mmddyy10.))) ||',&lt;BR /&gt;'||"c_los="||trim(left(put(c_los,3.)));&lt;BR /&gt;MPRINT(ARIINPCHART): format studysite studysite.;&lt;BR /&gt;ERROR: All variables in array list must be the same type, i.e., all numeric or character.&lt;BR /&gt;MPRINT(ARIINPCHART): if caseid in ('E1'.'K8','R05','ER') then delete;&lt;BR /&gt;MPRINT(ARIINPCHART): run;&lt;/P&gt;
&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.INPCR26 may be incomplete. When this step was stopped there were 0&lt;BR /&gt;observations and 7 variables.&lt;BR /&gt;WARNING: Data set WORK.INPCR26 was not replaced because this step was stopped.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;
&lt;/LI-SPOILER&gt;</description>
      <pubDate>Tue, 21 Mar 2023 15:58:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865474#M341789</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2023-03-21T15:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865484#M341793</link>
      <description>&lt;P&gt;This looks like a PROC SQL code error not a macro issue&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Remove the PROC SQL code from the macro&lt;/LI&gt;
&lt;LI&gt;Remove all macro references from the PROC SQL code&lt;/LI&gt;
&lt;LI&gt;Run the PROC SQL code&lt;/LI&gt;
&lt;LI&gt;Figure out why you are getting&amp;nbsp;&lt;BR /&gt;&lt;SPAN&gt;ERROR: The following columns were not found in the contributing tables: c_los.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;I'm guessing your input data (ds2INP) is missing columns (inptadmitdt and/or inptdischargedt)&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 16:48:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865484#M341793</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2023-03-21T16:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865487#M341795</link>
      <description>Although it's not in the dataset, I create a "c_los" in pro SQL</description>
      <pubDate>Tue, 21 Mar 2023 17:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865487#M341795</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2023-03-21T17:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865489#M341796</link>
      <description>&lt;P&gt;From now on, please include the log by clicking on the &amp;lt;/&amp;gt; icon and pasting the log into the window that appears.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1663012019648.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75161i0E71B1489A6C9839/image-size/large?v=v2&amp;amp;px=999" role="button" title="PaigeMiller_0-1663012019648.png" alt="PaigeMiller_0-1663012019648.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This preserves the formatting of the log. Like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ERROR: The following columns were not found in the contributing tables: c_los.&lt;/PRE&gt;
&lt;P&gt;There is no variable named c_los in the SAS data set being used by PROC SQL. So you get the error. (And by the way, this error has nothing to do with macros — because your code does not contain macros, it contains macro variables — but this error is a coding error, not a macro error). The fix is as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where scrdate ^=. and inptadmitdt ^=. and inptdischargedt ^=. and inptadmitdt ne '09SEP9999'd and inptdischargedt ne '09SEP9999'd
	   and (calculated c_los&amp;lt;0 or calculated c_los&amp;gt;100)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The word calculated tells PROC SQL to use a variable previously calculated by PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 17:03:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865489#M341796</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-21T17:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865491#M341798</link>
      <description>&lt;P&gt;Looks like a normal SAS error and should have nothing to do with any of the macro logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to reference the value of a variable defined in the list of columns selected you need to use the CALCULATED keyword.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where scrdate ^=.
  and inptadmitdt ^=.
  and inptdischargedt ^=.
  and inptadmitdt ne '09SEP9999'd
  and inptdischargedt ne '09SEP9999'd
  and (calculated c_los&amp;lt;0 or calculated c_los&amp;gt;100)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or replace the variable reference with the formula used to define the variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where scrdate ^=.
  and inptadmitdt ^=.
  and inptdischargedt ^=.
  and inptadmitdt ne '09SEP9999'd
  and inptdischargedt ne '09SEP9999'd
  and (intck('day',inptadmitdt, inptdischargedt)&amp;lt;0 or intck('day',inptadmitdt, inptdischargedt)&amp;gt;100)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Mar 2023 17:05:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865491#M341798</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-21T17:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865495#M341800</link>
      <description>Thanks for introducing the icon, someone taught me before, And I forgot.</description>
      <pubDate>Tue, 21 Mar 2023 17:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865495#M341800</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2023-03-21T17:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865497#M341801</link>
      <description>&lt;P&gt;Simplify the problem makes it simple to understand:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
	format 
		date1 date.
		date2 date.
	;
	do i=1 to 10 ;
		date1 =today()+int(ranuni(1)*30) ;
		date2 =today()+int(ranuni(2)*30) ;
		output have ;
	end ;
run ;

proc sql ;
	create table want as
 	select intck('day',date1, date2) as c_los
 	from have 
	where c_los&amp;lt; 10 ;
;
quit ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When you run that you will get the error you were getting&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;342  proc sql ;
343      create table want as
344      select intck('day',date1, date2) as c_los
345      from have
346      where c_los&amp;lt; 10 ;
ERROR: The following columns were not found in the contributing tables: c_los.
347  ;
348  quit ;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds

349  run ;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Mar 2023 17:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865497#M341801</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2023-03-21T17:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865498#M341802</link>
      <description>&lt;P&gt;Thank you so much for all of your valuable suggestions.&amp;nbsp; Unfortunately,&amp;nbsp; I can only allow one solution.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 17:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865498#M341802</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2023-03-21T17:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865510#M341810</link>
      <description>&lt;P&gt;You might want to consider this&lt;/P&gt;
&lt;PRE&gt;var1=catx(',',cats("scrdate=",put(scrdate,mmddyy10.))
             ,cats("inptadmitdt=",put(inptadmitdt,mmddyy10.))
             ,cats("inptdischargedt=",put(inptdischargedt,mmddyy10.)) 
             ,cats("c_los=",put(c_los,3.))
         )
;&lt;/PRE&gt;
&lt;P&gt;instead of that code with all the ||&amp;nbsp; and Trim(left()). The CATS function strips the values when concatenating strings. The CATX function will place the first parameter between the values from the other parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, the sort of coding that does&lt;/P&gt;
&lt;PRE&gt;data somesetname;
   set somesetname;
&amp;lt;other code&amp;gt;&lt;/PRE&gt;
&lt;P&gt;completely replaces the data source so if you have a logic problem, especially one buried in a macro, you will have a very hard time determining when the problem with values occurs because you cannot compare the start and end data sets.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 17:31:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error/m-p/865510#M341810</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-21T17:31:09Z</dc:date>
    </item>
  </channel>
</rss>

