<?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 parameter naming convention in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905555#M357664</link>
    <description>&lt;P&gt;First remark and my personal preference, but also _not_ my programming practice: &lt;EM&gt;as long as you _document_ what the parameter is - name it as you want.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second remark:, I would consider the following names:&lt;/P&gt;
&lt;P&gt;A - &lt;EM&gt;pathToFile &lt;/EM&gt;or&lt;EM&gt; filePath&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;B,C,D - &lt;EM&gt;path&lt;/EM&gt;, or maybe &lt;EM&gt;rootPath&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;E - is it a file or directory? if first then &lt;EM&gt;fileName&lt;/EM&gt; if the second &lt;EM&gt;dirName&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;F - &lt;EM&gt;fileName&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;G,H - &lt;EM&gt;ext&lt;/EM&gt; or &lt;EM&gt;extension&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But as I wrote "document the meaning in the first place".&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>Fri, 01 Dec 2023 09:53:14 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2023-12-01T09:53:14Z</dc:date>
    <item>
      <title>macro parameter naming convention</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905554#M357663</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Do you apply a naming convention for macro parameter names, names which are meaningful for the end user?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What name would you use in the following circumstances:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A: C:/mydir/mysubdir/helloworld.xlsx&lt;/P&gt;
&lt;P&gt;B: C:/mydir/mysubdir&lt;/P&gt;
&lt;P&gt;C: C:/mydir/mysubdir/&lt;/P&gt;
&lt;P&gt;D&amp;nbsp; C:/mydir/mysubdir/helloworld&lt;/P&gt;
&lt;P&gt;E: helloworld&lt;/P&gt;
&lt;P&gt;F: hellowworld.xlsx&lt;/P&gt;
&lt;P&gt;G: .xlsx&lt;/P&gt;
&lt;P&gt;H: xlsx&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question inspired from: &lt;A href="https://stackoverflow.com/questions/2235173/what-is-the-naming-standard-for-path-components" target="_blank" rel="noopener"&gt;https://stackoverflow.com/questions/2235173/what-is-the-naming-standard-for-path-components&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2023 09:39:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905554#M357663</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2023-12-01T09:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter naming convention</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905555#M357664</link>
      <description>&lt;P&gt;First remark and my personal preference, but also _not_ my programming practice: &lt;EM&gt;as long as you _document_ what the parameter is - name it as you want.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second remark:, I would consider the following names:&lt;/P&gt;
&lt;P&gt;A - &lt;EM&gt;pathToFile &lt;/EM&gt;or&lt;EM&gt; filePath&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;B,C,D - &lt;EM&gt;path&lt;/EM&gt;, or maybe &lt;EM&gt;rootPath&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;E - is it a file or directory? if first then &lt;EM&gt;fileName&lt;/EM&gt; if the second &lt;EM&gt;dirName&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;F - &lt;EM&gt;fileName&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;G,H - &lt;EM&gt;ext&lt;/EM&gt; or &lt;EM&gt;extension&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But as I wrote "document the meaning in the first place".&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>Fri, 01 Dec 2023 09:53:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905555#M357664</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-12-01T09:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter naming convention</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905556#M357665</link>
      <description>&lt;P&gt;One more remark, this thread seems to be "touching" dangerous area of "religion of SAS" &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19924"&gt;@FriedEgg&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2023 09:59:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905556#M357665</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-12-01T09:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter naming convention</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905559#M357666</link>
      <description>&lt;P&gt;Whatever floats your boat. With files, the name must convey its function (in, out, update). Document if the complete path or just the filename is needed.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2023 10:49:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905559#M357666</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-12-01T10:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter naming convention</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905573#M357673</link>
      <description>E is the file name without the extension.</description>
      <pubDate>Fri, 01 Dec 2023 13:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905573#M357673</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2023-12-01T13:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter naming convention</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905600#M357684</link>
      <description>&lt;P&gt;Only two of those values are valid for Macro variable &lt;STRONG&gt;names&lt;/STRONG&gt; so most of that is not usable as "parameter".&lt;/P&gt;
&lt;P&gt;You cannot have .&amp;nbsp; / :&amp;nbsp; in macro parameters (variable names) only letters, the underscore and digit characters are allowed and must start with letter or underscore.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Names of variables often have something to do with the role the parameter will play: filein for example for some sort of input file, fileout for an output file, msgtext for a parameter to hold some random text values for display. With that sort of thinking I don't really see any that come close especially without knowing exactly what said "macro" is supposed to do.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2023 15:49:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905600#M357684</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-12-01T15:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter naming convention</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905617#M357690</link>
      <description>&lt;P&gt;As others have noted you have conflated two topics here.&lt;/P&gt;
&lt;P&gt;One is the topic from your linked post, how to name the various components of a filename.&lt;/P&gt;
&lt;P&gt;The other is what are useful patterns for naming variables (whether normal dataset variable, or normal macro variables or macro variables used as macro parameters).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the later you should include the role that the value is being used for.&amp;nbsp; So perhaps an INFILE or OUTFILE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally I use directory instead of "folder".&amp;nbsp; I haven't used manila folders in a long time. In fact I don't even have any desk drawers or file cabinets in my office where I could store a folder.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The extension (or ext) on a file is the part after the last period.&amp;nbsp; If there is no period then the extension is blank.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if index(file,'.') then ext=scan(file,-1,'.');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Being too picky about whether to use a different name for a filename without a directory verses a filename with a directory included is probably not important in most uses.&amp;nbsp; Your macro should be able to adopt to either.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if the macro requires that the user pass in the directory name and name of the file within the directory separately then it should be pretty clear to the user that whatever name you used for the two parameters that they will be combined to make the full name.&amp;nbsp; And again you can make the macro smart enough to handle what you are passed.&amp;nbsp; For example you could append a / to the end of a directory if there is not one there already.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %length(&amp;amp;dir) %then %if not %index(/\,%qsubstr(&amp;amp;dir,%length(&amp;amp;dir)))
  %then %let dir=&amp;amp;dir/ ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Dec 2023 16:52:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905617#M357690</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-01T16:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter naming convention</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905830#M357722</link>
      <description>The values I've given in the question are for the macro parameter VALUES. I've not given any macro parameter name in the question. I was asking for suggestions for macro parameter names when the expected macro parameter values are as given in A... G</description>
      <pubDate>Sat, 02 Dec 2023 10:52:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905830#M357722</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2023-12-02T10:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter naming convention</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905848#M357733</link>
      <description>&lt;P&gt;Computers don't care what you name your variables.&amp;nbsp; You could name them &amp;amp;abdomen and &amp;amp;zebra for all a computer could "care".&amp;nbsp; The purpose of your question is to make your program more readable and easier to use for the next human that comes along.&amp;nbsp; Toward that end, here are some conventions I follow.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Every macro begins with a %global and a %local statement along these lines:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global gname1  /* description of the purpose of &amp;amp;gname1    */
        gname2  /* description of the purpose of &amp;amp;gname2    */
        ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The comments are usually one line long for each macro variable, but can be longer if needed.&amp;nbsp; And when using a monospace type, the asterisks line up so the reader can easily see the location of all the comments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The names themselves are intended to make the purpose clear to a human.&amp;nbsp; For example, these are vague names:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;file
vars&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;These are better names:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;n_vars
incoming_varlist &lt;BR /&gt;numeric_varlist
output_filetype&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;They take a little more typing, but they help the user understand the code as s/he looks through it, and lessen the need for the user to refer back to the comment sections when reading through the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just my opinion, FWIW.&amp;nbsp; Readability is in the eye of the beholder.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Dec 2023 17:21:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905848#M357733</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-12-02T17:21:45Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter naming convention</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905860#M357740</link>
      <description>&lt;P&gt;This is an interesting question, especially with the focus on the macro user:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;Do you apply a naming convention for macro parameter names, names which are meaningful for the end user?&lt;/BLOCKQUOTE&gt;
&lt;P&gt;On the one hand, as a macro developer, I think this is an important question, and one we should all consider.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On the other hand, as a SAS user, I feel like finding the best answer and using it consistently doesn't matter that much.&amp;nbsp; Even if you are developing something like a corporate macro library, where one might think that consistency in macro parameter names might be very important and helpful, the truth in SAS programming is that you end up using macros from a variety of sources, that all have different naming styles.&amp;nbsp; So as macro user, you are used to having to look at macro code to figure out the parameters etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, I do think there is value in using consistent names, partly as help to the user, and partly as help to the developer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I often have a macro parameter PATH, for:&lt;/P&gt;
&lt;P&gt;B: C:/mydir/mysubdir&lt;/P&gt;
&lt;P&gt;C: C:/mydir/mysubdir/&lt;/P&gt;
&lt;P&gt;I'm inconsistent about whether or not the value passed to PATH should end with a trailing /.&amp;nbsp; Generally I think it "should".&amp;nbsp; But in the macro code, I don't really like the look of:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;path&amp;amp;file&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I just like the look of:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;path/&amp;amp;file&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I think Windows and Linux may not care about //, even if it looks weird.&amp;nbsp; As Tom said, the best answer for path is to allow the user to pass a value with our without trailing /, and have the macro accommodate it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also often have a parameter named FILE for:&lt;/P&gt;
&lt;P&gt;A: C:/mydir/mysubdir/helloworld.xlsx&lt;/P&gt;
&lt;P&gt;hiworld (this is a fileref, not the name of a file without an extension)&lt;/P&gt;
&lt;P&gt;F: hellowworld.xlsx&lt;/P&gt;
&lt;P&gt;Usually the value to be passed for FILE is either a full path to a file, or a fileref (the user can choose).&amp;nbsp; &amp;nbsp;It's rare that I would pass just a file name (helloworld.xlsx).&amp;nbsp; But if a macro has a PATH parameter, then it's possible that a FILE parameter would be just a file name, because the user has already specified the path to the file.&amp;nbsp; It doesn't bother me that a FILE parameter could be the full path to the file, just the filename, or a fileref.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On occasion I have a parameter EXT or EXTENSION:&lt;/P&gt;
&lt;P&gt;H: xlsx&lt;/P&gt;
&lt;P&gt;There were probably times when I would ask a user to include a dot in the extension, but to my mind the dot is not part on an extension.&amp;nbsp; But like trailing / issue for path, for a user-friendly macro it's trivial to detect whether the user has provided a leading dot or not, and handle it accordingly.&amp;nbsp; So you don't need different parameter names for EXTwithDot EXTwithoutDot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think I've ever written a macro parameter that asked a user to provide a value for a file name without an extension:&lt;/P&gt;
&lt;P&gt;D C:/mydir/mysubdir/helloworld&lt;/P&gt;
&lt;P&gt;E: helloworld&lt;/P&gt;
&lt;P&gt;Just looking at those, the first value looks like a path, and the second looks like a directory or subdirectory to me, these values don't look like files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if I were to pick a standard I use inconsistently, it would be FILE, PATH, and EXT.&amp;nbsp; &amp;nbsp; But if you looked at macros I've developed, you'd find plenty of FILENAME, INFILE, DIR, FOLDER, etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As IDE's get smarter, they make some of this easier for the user.&amp;nbsp; For example in EG, if you define a macro like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro foo(
  path= /*path to file, with trailing / */
 ,file= /*file name in quotes with extension or fileref*/
);
  %* ... ;
%mend foo;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When&amp;nbsp; a user invokes the macro, some of those tips will be available.&amp;nbsp; It's not perfect, but it's something.&amp;nbsp; I don't know if there is something like that in Studio, or the VS code extension, but would hope so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Dec 2023 18:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-parameter-naming-convention/m-p/905860#M357740</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-12-02T18:55:13Z</dc:date>
    </item>
  </channel>
</rss>

