<?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: _N_ troubles in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/N-troubles/m-p/293844#M61238</link>
    <description>First, you have your rules row by row, then transposing them to single line, and then put it to the file row by row...? Is there any more logic to be added to this later...?&lt;BR /&gt;&lt;BR /&gt;Second, no need for using the macro function here, the data step counterpart will probably do.</description>
    <pubDate>Wed, 24 Aug 2016 20:03:25 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2016-08-24T20:03:25Z</dc:date>
    <item>
      <title>_N_ troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/N-troubles/m-p/293837#M61236</link>
      <description>&lt;P&gt;Hi. I need some help resolving an error in my program. I've provided the full program code below so that you can see it in action yourself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my program I build a macro variable that contains a list of rules seperated by # signs. In the program below the macro variable value looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A.ACTUAL_DLVRY_DATE IS NULL AND B.ACTUAL_DLVRY_DATE IS NOT NULL#A.ACTUAL_DLVRY_DATE &amp;gt; B.ACTUAL_DLVRY_DATE&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I can use the %scan function to pull individual rules from the list.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;the_rule=%scan(&amp;amp;rule_list, 1,#);      &lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;the_rule=%scan(&amp;amp;rule_list, 2,#);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;These statements pull the rule values accordingly to the increment value:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A.ACTUAL_DLVRY_DATE IS NULL AND B.ACTUAL_DLVRY_DATE IS NOT NULL&lt;/P&gt;&lt;P&gt;A.ACTUAL_DLVRY_DATE &amp;gt; B.ACTUAL_DLVRY_DATE&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I attempt to alter this statement to make it more dynamic using _N_ it errors out. See the error below.&amp;nbsp;I'm doing this so that _n_ automatically increments for each record in my dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;the_rule=%scan(&amp;amp;rule_list, _n_,#);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error looks like the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;2201 data _null_;
2202 set QueryRules end=eof;
2203 by Rule_Order;
2204 file '/home/ssbuechl/input_whens.sas';
2205 the_rule=%scan(&amp;amp;rule_list, _n_,#);
-
22
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition
was: _n_
ERROR: Argument 2 to macro function %SCAN is not a number.
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
a missing value, INPUT, PUT.
2206 put THE RULE: the_rule;
2207 run;
NOTE: The SAS System stopped processing this step because of errors.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the complete program you can run yourself...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rsubmit;

data QueryRules;
infile cards dsd dlm='|' truncover ;
informat analysis_desc $34. rule $64.;
input analysis_desc $ rule $ rule_order;
cards;
ACTUAL DELIVERY DATE MISSING IN IV|A.ACTUAL_DLVRY_DATE IS NULL AND B.ACTUAL_DLVRY_DATE IS NOT NULL|1
ACTUAL DELIVERY DATE LATER IN IV|A.ACTUAL_DLVRY_DATE &amp;gt; B.ACTUAL_DLVRY_DATE|1.5
run;

proc print; run;

* Sort prep for call to BuildQueryData macro below ;
proc sort data=QueryRules;
    by rule_order;
run;

proc sql;
select trim(rule) into : rule_list separated by '#' from QueryRules;
quit;

%PUT CHECK: RULE_LIST: &amp;amp;RULE_LIST;

data _null_;
   set QueryRules end=eof;
   by Rule_Order;
   file '/home/ssbuechl/input_whens.sas';
   the_rule=%scan(&amp;amp;rule_list, _n_,#);
   put THE RULE: the_rule;
run;

endrsubmit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Aug 2016 19:52:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/N-troubles/m-p/293837#M61236</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-08-24T19:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: _N_ troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/N-troubles/m-p/293844#M61238</link>
      <description>First, you have your rules row by row, then transposing them to single line, and then put it to the file row by row...? Is there any more logic to be added to this later...?&lt;BR /&gt;&lt;BR /&gt;Second, no need for using the macro function here, the data step counterpart will probably do.</description>
      <pubDate>Wed, 24 Aug 2016 20:03:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/N-troubles/m-p/293844#M61238</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-08-24T20:03:25Z</dc:date>
    </item>
    <item>
      <title>Re: _N_ troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/N-troubles/m-p/293846#M61239</link>
      <description>&lt;P&gt;DATA steps do not use macro functions to process the data.&amp;nbsp; With a couple of changes, you could use SCAN instead of %SCAN:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the_rule = scan("&amp;amp;rule_list", _n_, '#');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data steps require text strings to be surrounded by quotes (macro language does not).&amp;nbsp; Be sure to use double quotes the first time, but either single or double quotes around # would work.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2016 20:11:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/N-troubles/m-p/293846#M61239</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-08-24T20:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: _N_ troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/N-troubles/m-p/293847#M61240</link>
      <description>&lt;P&gt;Macro function? &amp;nbsp;Which one?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2016 20:11:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/N-troubles/m-p/293847#M61240</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-08-24T20:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: _N_ troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/N-troubles/m-p/293848#M61241</link>
      <description>Thanks so much!</description>
      <pubDate>Wed, 24 Aug 2016 20:14:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/N-troubles/m-p/293848#M61241</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-08-24T20:14:44Z</dc:date>
    </item>
    <item>
      <title>Re: _N_ troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/N-troubles/m-p/293850#M61242</link>
      <description>&lt;P&gt;Here's an idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show us the actual values you are building from (&amp;nbsp;the data set you use to make this complex variable and processing problem), a small set would do, AND the desired SAS code you want that data set to create.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have asked multiple questions with this same data, bad mixing of MACRO code inside DATASTEP and have never provided what the actual final output for a small set of it should actually look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I really believe that you have added lots of headaches by picking an approach (combining those values) when a more direct result would be possible without it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2016 20:18:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/N-troubles/m-p/293850#M61242</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-08-24T20:18:29Z</dc:date>
    </item>
  </channel>
</rss>

