<?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 Statement is not valid - Error 180-322 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Statement-is-not-valid-Error-180-322/m-p/66281#M14397</link>
    <description>I inherited some SAS scripts written by a non-programmer.  I am new to SAS and need to make a change. Here is a simple piece of code that 'should' choose a SQL statement based on the predefined variable - ttest:&lt;BR /&gt;
&lt;BR /&gt;
   proc sql;&lt;BR /&gt;
     if ttype = 'I' then&lt;BR /&gt;
       do;&lt;BR /&gt;
         create view datavalv as&lt;BR /&gt;
         select T.data_validity_code, &lt;BR /&gt;
                R.sak_feeding_test_res&lt;BR /&gt;
         from TIMD.feeding_test_results T&lt;BR /&gt;
              left join TIMD.feeding_test_remarks R on&lt;BR /&gt;
               (T.sak_feeding_test_res = R.sak_feeding_test_res)&lt;BR /&gt;
         where T.test_num = &amp;amp;test;&lt;BR /&gt;
       end;&lt;BR /&gt;
     else&lt;BR /&gt;
       do;&lt;BR /&gt;
         create view datavalv as&lt;BR /&gt;
         select data_validity_code, &lt;BR /&gt;
                sak_outside_feed_res as sak_feeding_test_res&lt;BR /&gt;
         from TIMD.outside_feeding_results &lt;BR /&gt;
         where outside_feeding_results.test_num = &amp;amp;test;&lt;BR /&gt;
       end;&lt;BR /&gt;
     quit;&lt;BR /&gt;
&lt;BR /&gt;
here is a snippet of the error reported:&lt;BR /&gt;
&lt;BR /&gt;
709                 (T.sak_feeding_test_res = R.sak_feeding_test_res)&lt;BR /&gt;
710           where T.test_num = &amp;amp;test;&lt;BR /&gt;
NOTE: SQL view WORK.DATAVALV has been defined.&lt;BR /&gt;
711         end;&lt;BR /&gt;
            ---&lt;BR /&gt;
            180&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;
&lt;BR /&gt;
712       else&lt;BR /&gt;
          ----&lt;BR /&gt;
          180&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;
&lt;BR /&gt;
713         do;&lt;BR /&gt;
&lt;BR /&gt;
Should be simple, but I am having no success.</description>
    <pubDate>Wed, 17 Dec 2008 15:25:41 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-12-17T15:25:41Z</dc:date>
    <item>
      <title>Statement is not valid - Error 180-322</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Statement-is-not-valid-Error-180-322/m-p/66281#M14397</link>
      <description>I inherited some SAS scripts written by a non-programmer.  I am new to SAS and need to make a change. Here is a simple piece of code that 'should' choose a SQL statement based on the predefined variable - ttest:&lt;BR /&gt;
&lt;BR /&gt;
   proc sql;&lt;BR /&gt;
     if ttype = 'I' then&lt;BR /&gt;
       do;&lt;BR /&gt;
         create view datavalv as&lt;BR /&gt;
         select T.data_validity_code, &lt;BR /&gt;
                R.sak_feeding_test_res&lt;BR /&gt;
         from TIMD.feeding_test_results T&lt;BR /&gt;
              left join TIMD.feeding_test_remarks R on&lt;BR /&gt;
               (T.sak_feeding_test_res = R.sak_feeding_test_res)&lt;BR /&gt;
         where T.test_num = &amp;amp;test;&lt;BR /&gt;
       end;&lt;BR /&gt;
     else&lt;BR /&gt;
       do;&lt;BR /&gt;
         create view datavalv as&lt;BR /&gt;
         select data_validity_code, &lt;BR /&gt;
                sak_outside_feed_res as sak_feeding_test_res&lt;BR /&gt;
         from TIMD.outside_feeding_results &lt;BR /&gt;
         where outside_feeding_results.test_num = &amp;amp;test;&lt;BR /&gt;
       end;&lt;BR /&gt;
     quit;&lt;BR /&gt;
&lt;BR /&gt;
here is a snippet of the error reported:&lt;BR /&gt;
&lt;BR /&gt;
709                 (T.sak_feeding_test_res = R.sak_feeding_test_res)&lt;BR /&gt;
710           where T.test_num = &amp;amp;test;&lt;BR /&gt;
NOTE: SQL view WORK.DATAVALV has been defined.&lt;BR /&gt;
711         end;&lt;BR /&gt;
            ---&lt;BR /&gt;
            180&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;
&lt;BR /&gt;
712       else&lt;BR /&gt;
          ----&lt;BR /&gt;
          180&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;
&lt;BR /&gt;
713         do;&lt;BR /&gt;
&lt;BR /&gt;
Should be simple, but I am having no success.</description>
      <pubDate>Wed, 17 Dec 2008 15:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Statement-is-not-valid-Error-180-322/m-p/66281#M14397</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-17T15:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Statement is not valid - Error 180-322</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Statement-is-not-valid-Error-180-322/m-p/66282#M14398</link>
      <description>Hi:&lt;BR /&gt;
  Two questions:&lt;BR /&gt;
1) Was the code working before you inherited it? Did it ever successfully generate output? Or is this pseudo-code that conceptually shows the type of conditional processing that should take place?&lt;BR /&gt;
                  &lt;BR /&gt;
2) Did you remove any % or &amp;amp; punctuation from the code or any %macro or %mend statements?&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 17 Dec 2008 15:45:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Statement-is-not-valid-Error-180-322/m-p/66282#M14398</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-12-17T15:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Statement is not valid - Error 180-322</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Statement-is-not-valid-Error-180-322/m-p/66283#M14399</link>
      <description>Sorry, I was not clear.  I added the if/else structure.  I have to make this script generic so it will run internal or external test (they have different tables and columns).&lt;BR /&gt;
Here is the original 'Proc sql':&lt;BR /&gt;
proc sql;&lt;BR /&gt;
   create  view datavalv as&lt;BR /&gt;
   select  data_validity_code, feeding_test_remarks.sak_feeding_test_res&lt;BR /&gt;
     from  tims.feeding_test_results left join tims.feeding_test_remarks&lt;BR /&gt;
       on  feeding_test_results.sak_feeding_test_res = feeding_test_remarks.sak_feeding_test_res&lt;BR /&gt;
  where  feeding_test_results.test_num = &amp;amp;test;&lt;BR /&gt;
   quit;</description>
      <pubDate>Wed, 17 Dec 2008 15:53:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Statement-is-not-valid-Error-180-322/m-p/66283#M14399</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-17T15:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: Statement is not valid - Error 180-322</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Statement-is-not-valid-Error-180-322/m-p/66284#M14400</link>
      <description>Hi:&lt;BR /&gt;
  Where will TTYPE come from? Is it already in the data or is it a parameter that the person using the code will supply? How do you envision TTYPE being supplied? It looks to me as though the data sets being processed determine the type of SQL code.&lt;BR /&gt;
&lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 17 Dec 2008 15:57:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Statement-is-not-valid-Error-180-322/m-p/66284#M14400</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-12-17T15:57:23Z</dc:date>
    </item>
    <item>
      <title>Re: Statement is not valid - Error 180-322</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Statement-is-not-valid-Error-180-322/m-p/66285#M14401</link>
      <description>Here is the tetst specific code from the top of the script:&lt;BR /&gt;
&lt;BR /&gt;
    %let ttype = 'I';                     ** Internal/External flag&lt;BR /&gt;
    %let test = 43271;                ** change test number&lt;BR /&gt;
    %let num_anml = 25;            ** change number of animals</description>
      <pubDate>Wed, 17 Dec 2008 16:01:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Statement-is-not-valid-Error-180-322/m-p/66285#M14401</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-17T16:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: Statement is not valid - Error 180-322</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Statement-is-not-valid-Error-180-322/m-p/66286#M14402</link>
      <description>Hi:&lt;BR /&gt;
  First some terminology -- the SAS programming language is not a scripting language. I think of a script program (like JavaScript or PHP or Perl) as something that executes immediately and is &lt;B&gt;not&lt;/B&gt; compiled. &lt;BR /&gt;
&lt;BR /&gt;
SAS code is compiled, and then, if free of compile errors, is executed. In my mind, that makes SAS something OTHER than a scripting language like JavaScript. I'd call a group of SAS statements a program, not a script. A SAS program can be composed of 1 step or of multiple steps. However, each step is compiled before it is executed.&lt;BR /&gt;
&lt;BR /&gt;
A SAS program is basically composed of DATA steps and PROCEDURE steps (most commonly called PROC steps). (along with option statements and other global statements that have an impact on how the program is executed or how the output is treated) A DATA step program allows you to use SAS language syntax, such as IF/THEN statements, assignment statements, ARRAYs, DO loops, etc. &lt;BR /&gt;
           &lt;BR /&gt;
A PROC step program allows you to use "canned" statements that have pre-defined ways of operating. So for example, PROC MEANS has a VAR statement; PROC SQL has a SELECT statment. Neither PROC MEANS nor PROC SQL (for example) allow an IF statement to be used inside their syntax. Regular SAS IF statements belong to a DATA step program. So you got an error because you used an IF statement in the wrong place.&lt;BR /&gt;
&lt;BR /&gt;
However, another rule of the SAS programming language is that you can't mix DATA step syntax and PROC syntax...so for example, you CANNOT do this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
DATA TEST;&lt;BR /&gt;
  if TTEST = 'T' then do;&lt;BR /&gt;
    proc sql;&lt;BR /&gt;
   ......... more proc sql code .........&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
That's because DATA step programs and PROC step programs are "self-contained". So how do you define and generate generic reusable code??? Enter the SAS Macro facility.&lt;BR /&gt;
   &lt;BR /&gt;
There is an additional piece of SAS language called the SAS Macro Facility. The SAS Macro facility is used to perform text substitution and to help you generate valid code that will compile and then execute. Just like a DATA step program has an IF statement, you can use a %IF statement inside a MACRO program to generate program code conditionally. &lt;BR /&gt;
&lt;BR /&gt;
What happens is that the Macro facility grabs any macro "triggers" like % or &amp;amp; and resolves them BEFORE any code is compiled. What the compiler sees is the resolved SAS code. The SAS Macro facility doesn't "run" anything -- it only takes a macro program or macro variable references and resolves the program into valid SAS statements or takes the macro variable references and resolves them in code (like a TITLE statement or other statements).&lt;BR /&gt;
&lt;BR /&gt;
A good tutorial or place to start with the SAS Macro facility is here:&lt;BR /&gt;
 &lt;A href="http://www2.sas.com/proceedings/sugi28/056-28.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi28/056-28.pdf&lt;/A&gt; &lt;BR /&gt;
&lt;BR /&gt;
Of course the Macro documentation is good, too, and there's a lot to Google on SAS Global Forum papers about using SAS Macro programs to generate reusable, generic code. I suggest you start with the tutorial and if that doesn't help, then look for some other examples of using SAS Macro programs to conditionally generate program statements.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 17 Dec 2008 16:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Statement-is-not-valid-Error-180-322/m-p/66286#M14402</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-12-17T16:28:30Z</dc:date>
    </item>
  </channel>
</rss>

