<?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 naming? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Macro-naming/m-p/332376#M62776</link>
    <description>&lt;P&gt;%macro chisqrun2 (&amp;amp;X1, &amp;amp;Y1);&lt;/P&gt;
&lt;P&gt;is the start of a macro definition. As such the processor really does not want to compile a macro that it does not know the name of the VARIABLES that it well be using.&lt;/P&gt;
&lt;P&gt;the definitions should use&lt;/P&gt;
&lt;P&gt;%macro chisqrun2 (X1, Y1);&lt;/P&gt;
&lt;P&gt;so that the first position will be referenced inside the macro as &amp;amp;x1 and the second as &amp;amp;y1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Feb 2017 22:00:25 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-02-13T22:00:25Z</dc:date>
    <item>
      <title>Macro naming?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-naming/m-p/332306#M62769</link>
      <description>&lt;P&gt;Hello:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to write a macro to representing my files name because the program is needed to&amp;nbsp;run many times. &amp;nbsp;However, the system showed syntax error. &amp;nbsp;Please help. &amp;nbsp;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let libname=RF;&lt;BR /&gt;%let filename=NG;&lt;BR /&gt;%let year=2013;&lt;BR /&gt;%let number=02;&lt;/P&gt;&lt;P&gt;% X1=wage;&lt;/P&gt;&lt;P&gt;% Y1=salary;&lt;/P&gt;&lt;P&gt;data &amp;amp;libname.&amp;amp;filename&amp;amp;year(&amp;amp;number+2);&lt;BR /&gt;set &amp;amp;libname.&amp;amp;filename&amp;amp;year&amp;amp;number;&lt;BR /&gt;if &amp;amp;Y1 in (1,2) and &amp;amp;X1 in (1,2,5,6);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;51 data &amp;amp;libname.&amp;amp;filename&amp;amp;year(&amp;amp;number+2);&lt;BR /&gt;-&lt;BR /&gt;200&lt;BR /&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;52 set &amp;amp;libname.&amp;amp;filename&amp;amp;year&amp;amp;number;&lt;BR /&gt;- - -&lt;BR /&gt;22 200 200&lt;BR /&gt;200&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, CUROBS, END,&lt;BR /&gt;INDSNAME, KEY, KEYRESET, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.&lt;/P&gt;&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference LIBNAME not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference FILENAME not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference YEAR not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference NUMBER not resolved.&lt;BR /&gt;ERROR: File WORK.FILENAME.DATA does not exist.&lt;BR /&gt;ERROR: File WORK.YEAR.DATA does not exist.&lt;BR /&gt;ERROR: File WORK.NUMBER.DATA does not exist.&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, -, :, ;,&lt;BR /&gt;CUROBS, END, INDSNAME, KEY, KEYRESET, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 19:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-naming/m-p/332306#M62769</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-02-13T19:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macro naming?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-naming/m-p/332311#M62770</link>
      <description>&lt;P&gt;There are few problems I can see here. Does this code work better?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let libname=RF;
%let filename=NG;
%let year=2013;
%let number=02;
%let X1=wage;
%let Y1=salary;
data &amp;amp;libname..&amp;amp;filename&amp;amp;year%eval(&amp;amp;number+2);
set &amp;amp;libname..&amp;amp;filename&amp;amp;year&amp;amp;number;
if &amp;amp;Y1 in (1,2) and &amp;amp;X1 in (1,2,5,6);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You missed out the&amp;nbsp;&lt;EM&gt;%let&lt;/EM&gt; commands for&amp;nbsp;&lt;EM&gt;wage&lt;/EM&gt; and&amp;nbsp;&lt;EM&gt;salary&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;When you have a macro variable that must be suffixed with a full-stop, you need two of them:&amp;nbsp;&lt;EM&gt;&amp;amp;libname..&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;To make sure that number has 2 added to it, you need to use &amp;nbsp;&lt;EM&gt;%eval&lt;/EM&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 19:53:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-naming/m-p/332311#M62770</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-02-13T19:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Macro naming?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-naming/m-p/332312#M62771</link>
      <description>&lt;P&gt;There are few problems I can see here. Does this code work better?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let libname=RF;
%let filename=NG;
%let year=2013;
%let number=02;
%let X1=wage;
%let Y1=salary;
data &amp;amp;libname..&amp;amp;filename&amp;amp;year%eval(&amp;amp;number+2);
set &amp;amp;libname..&amp;amp;filename&amp;amp;year&amp;amp;number;
if &amp;amp;Y1 in (1,2) and &amp;amp;X1 in (1,2,5,6);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You missed out the&amp;nbsp;&lt;EM&gt;%let&lt;/EM&gt; commands for&amp;nbsp;&lt;EM&gt;wage&lt;/EM&gt; and&amp;nbsp;&lt;EM&gt;salary&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;When you have a macro variable that must be suffixed with a full-stop, you need two of them:&amp;nbsp;&lt;EM&gt;&amp;amp;libname..&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;To make sure that number has 2 added to it, you need to use &lt;EM&gt;%eval&lt;/EM&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 19:55:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-naming/m-p/332312#M62771</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-02-13T19:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: Macro naming?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-naming/m-p/332335#M62773</link>
      <description>&lt;P&gt;Actually, the following is my macro codes. &amp;nbsp;However, after I ran it, I found another syntax again under %macro. &amp;nbsp; Please see below. &amp;nbsp;How to fix it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let libname=RF;&lt;BR /&gt;%let filename=NG;&lt;BR /&gt;%let year=2013;&lt;BR /&gt;%let number=02;&lt;BR /&gt;%let X1=wage;&lt;BR /&gt;%let Y1=salary;&lt;BR /&gt;%macro chisqrun2 (&amp;amp;X1, &amp;amp;Y1);&lt;/P&gt;&lt;P&gt;ERROR: Invalid macro parameter name &amp;amp;. It should be a valid SAS identifier no longer than 32&lt;BR /&gt;characters.&lt;BR /&gt;ERROR: A dummy macro will be compiled.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc freq data=&amp;amp;libname..&amp;amp;filename&amp;amp;year&amp;amp;number;&lt;BR /&gt;table &amp;amp;X1 * &amp;amp;Y1 / chisq;&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data &amp;amp;libname..&amp;amp;filename&amp;amp;year%eval(&amp;amp;number+2);;&lt;BR /&gt;set &amp;amp;libname..&amp;amp;filename&amp;amp;year&amp;amp;number;&lt;BR /&gt;if &amp;amp;Y1 in (1,2) and &amp;amp;X1 in (1,2,5,6);&lt;BR /&gt;run;&lt;BR /&gt;%chisqrun2 (&amp;amp;X1,&amp;amp;Y1);&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 20:50:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-naming/m-p/332335#M62773</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-02-13T20:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: Macro naming?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-naming/m-p/332376#M62776</link>
      <description>&lt;P&gt;%macro chisqrun2 (&amp;amp;X1, &amp;amp;Y1);&lt;/P&gt;
&lt;P&gt;is the start of a macro definition. As such the processor really does not want to compile a macro that it does not know the name of the VARIABLES that it well be using.&lt;/P&gt;
&lt;P&gt;the definitions should use&lt;/P&gt;
&lt;P&gt;%macro chisqrun2 (X1, Y1);&lt;/P&gt;
&lt;P&gt;so that the first position will be referenced inside the macro as &amp;amp;x1 and the second as &amp;amp;y1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 22:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-naming/m-p/332376#M62776</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-13T22:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro naming?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-naming/m-p/332520#M62778</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are using frequently that kind of dataset naming, maybe you would benefit by creating a macro "function" like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let libname=RF;
%let filename=NG;
%let year=2013;
%let number=02;
%let X1=wage;
%let Y1=salary;

%macro mFilename(mLIBNAME=&amp;amp;LIBNAME,mFILENAME=&amp;amp;FILENAME,mYEAR=&amp;amp;YEAR,mNUMBER=&amp;amp;NUMBER);
&amp;amp;mLIBNAME%str(.)&amp;amp;mFILENAME&amp;amp;mYEAR%sysfunc(putn(&amp;amp;mNUMBER,z2.))
%mend mFilename; * return my dataset name;

data %mFilename(mNUMBER=%eval(&amp;amp;NUMBER+2));
set %mFilename();;
if &amp;amp;Y1 in (1,2) and &amp;amp;X1 in (1,2,5,6);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Macro mFilename will build and return the name for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For convenience It's&amp;nbsp;using named parameters and defaulting to macro vars LIBNAME, FILENAME, YEAR and NUMBER.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 09:28:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-naming/m-p/332520#M62778</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-02-14T09:28:23Z</dc:date>
    </item>
  </channel>
</rss>

