<?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 Variable name with numbers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870757#M343944</link>
    <description>&lt;P&gt;Thank you so much! i got it&lt;/P&gt;</description>
    <pubDate>Thu, 20 Apr 2023 12:27:50 GMT</pubDate>
    <dc:creator>kindbe17</dc:creator>
    <dc:date>2023-04-20T12:27:50Z</dc:date>
    <item>
      <title>Macro Variable name with numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870753#M343941</link>
      <description>&lt;P&gt;Hi, who can help me how to&amp;nbsp;shown below (Note that “1987 Salary” ) with macro variable, i am trying this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;....%let n=1987. Salary;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;data newone (rename =(_Name_=Statistic Col1=&amp;amp;n.));&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;set newdat1;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;run;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but Sas tells me&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt;Variable name 1987. is not valid&lt;/EM&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1987 Salary&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;XX&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;XX.X (XX.XX)&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;XX.X&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;XX, XX&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 20 Apr 2023 12:17:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870753#M343941</guid>
      <dc:creator>kindbe17</dc:creator>
      <dc:date>2023-04-20T12:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable name with numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870756#M343943</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let n=1987. Salary;
data newone (rename =(_Name_=Statistic Col1=&amp;amp;n.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can't have a period or a space in a SAS variable name. Your SAS variable names cannot begin with digits. On the other hand, the code below works:&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;%let n=Salary1987;
data newone (rename =(_Name_=Statistic Col1=&amp;amp;n.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Although the above works, I think here we have a situation where calendar information is being placed into a variable name, which I think is almost always a poor choice. If you are looking for a column to identify values in a given year, you would be better off using PROC REPORT to generate this, rather than hard-coding the year into a variable name.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2023 12:22:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870756#M343943</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-20T12:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable name with numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870757#M343944</link>
      <description>&lt;P&gt;Thank you so much! i got it&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2023 12:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870757#M343944</guid>
      <dc:creator>kindbe17</dc:creator>
      <dc:date>2023-04-20T12:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable name with numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870759#M343946</link>
      <description>&lt;P&gt;In genaeral, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote SAS does not allow periods or spaces in variables name.&lt;/P&gt;
&lt;P&gt;The general rule is: letters(roman alphabet, 26), underscore ("_") and digits (0-9) are only allowed in variables names. Plus: up to 32 characters and firs can by only letter or underscore.&lt;/P&gt;
&lt;P&gt;The general rule is &lt;STRONG&gt;good programming practice&lt;/STRONG&gt; in this case, but as you my expect there is also bad programming practice which involves option: validvarname, see the link to doc.:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lesysoptsref/p124dqdk8zoqu3n1r4nsfqu5vx52.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lesysoptsref/p124dqdk8zoqu3n1r4nsfqu5vx52.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In code it would look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data newdat1;
_Name_=1; Col1=2;
run;

OPTIONS VALIDVARNAME=ANY;

%let n='1987. Salary'n; /* &amp;lt;---------- text is in quotes and has "n" right after it, like the sas date literal has "d" [ '17jan2135'd ]*/
data newone (rename =(_Name_=Statistic Col1=&amp;amp;n.));
set newdat1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But as I wrote, it is bad programming practice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2023 12:31:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870759#M343946</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-04-20T12:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable name with numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870760#M343947</link>
      <description>&lt;P&gt;So just to be clear, I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;, it is bad programming practice for the reason he states, and it is bad programming practice for the reason I stated. An example of double bad programming practice!&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2023 12:33:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870760#M343947</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-20T12:33:44Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable name with numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870761#M343948</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441989"&gt;@kindbe17&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to do this, if you don't want to go the Proc Report route as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;has suggested, would be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;
%let n=1997 Salary;
data have;
 col1=222;
run;
data want;
 set have(rename=(col1="&amp;amp;n"n));
run;
proc print data=want noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;TABLE width="82"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="82"&gt;1997 Salary&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;222&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2023 12:34:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870761#M343948</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2023-04-20T12:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable name with numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870763#M343949</link>
      <description>&lt;P&gt;Of course,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13868"&gt;@AhmedAl_Attar&lt;/a&gt;&amp;nbsp;is correct in the sense that this will work ... however, it is impossible for me to see how &lt;FONT face="courier new,courier"&gt;'1987. Salary'n&lt;/FONT&gt; is in any way a better or more useful variable name than &lt;FONT face="courier new,courier"&gt;Salary1987&lt;/FONT&gt;. It is, however a more difficult name to type, as extra characters are required and at least for me, typing quotes is a place where I make an inordinate number of typographical errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now I said this isn't a better or more useful variable name, emphasis on &lt;FONT color="#FF0000"&gt;variable name&lt;/FONT&gt;, but if you are creating a report, it is true that a properly worded column heading is a good thing to do, emphasis on &lt;FONT color="#FF0000"&gt;column heading&lt;/FONT&gt;. Column headings in reports do not need to be the variable name. And so again, PROC REPORT seems to be a tool that allows this, without having to work extra hard to create and type variable names. In fact, having columns in PROC REPORT with calendar information in the column heading is a lot easier than trying to force DATA set variables to have the proper variable names.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2023 12:53:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870763#M343949</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-20T12:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable name with numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870769#M343954</link>
      <description>&lt;P&gt;Dear Sir,&lt;/P&gt;&lt;P&gt;Thank you very much . this is a huge work you do for us.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2023 13:25:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870769#M343954</guid>
      <dc:creator>kindbe17</dc:creator>
      <dc:date>2023-04-20T13:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable name with numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870770#M343955</link>
      <description>&lt;P&gt;Thank you very-very much for explaining and givving me such a great example, i have already used it in my task &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2023 13:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870770#M343955</guid>
      <dc:creator>kindbe17</dc:creator>
      <dc:date>2023-04-20T13:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable name with numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870792#M343962</link>
      <description>&lt;P&gt;I just wanted to confirm, I'm in total agreement with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&amp;amp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;when it comes to variable names and naming strategies.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My approach was trying to showoff SAS's versatility and capability to match the flexibility other software packages and programs, namely MS Excel, offer their users.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if I were to approach this as a pure SAS "developer", then I would 100% follow the SAS native variable naming rules, and assign variable label= attribute in order to hold a descriptive column header that can be displayed in SAS generated outputs (Report, Graph, listing...)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just saying&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2023 14:07:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-name-with-numbers/m-p/870792#M343962</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2023-04-20T14:07:15Z</dc:date>
    </item>
  </channel>
</rss>

