Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • syntax [varname] and syntax [varlist] with no argument give "too many variables specified error'

    What am I doing wrong here? It's undoubtedly something too obvious for me to see.

    .ÿversionÿ14.2

    .ÿ
    .ÿclearÿ*

    .ÿsetÿmoreÿoff

    .ÿ
    .ÿprogramÿdefineÿshowm
    ÿÿ1.ÿÿÿÿÿÿÿÿÿversionÿ14.2
    ÿÿ2.ÿÿÿÿÿÿÿÿÿsyntaxÿ[varname]
    ÿÿ3.ÿ
    .ÿend

    .ÿ
    .ÿsysuseÿauto
    (1978ÿAutomobileÿData)

    .ÿ
    .ÿshowmÿforeign

    .ÿ
    .ÿshowm
    tooÿmanyÿvariablesÿspecified
    r(103);

    endÿofÿdo-file

    r(103);

    .


    The help file for syntax indicates that optional variable name and variable list are acceptable, but it seems not to work unless a variable is supplied.
    Attached Files

  • #2
    Joseph: I can't copy and paste your code without strange fill characters being imported: please use CODE delimiters.

    How about this? Optional varname means that all variables are used by default, but that clashes with the prescription of a single variable name. Otherwise put, there can't be an obvious default variable name unless the dataset consists of a single variable. This works:


    Code:
    clear
    
    program showm
    version 14.2
    syntax [varname]
    end
    
    sysuse auto, clear
    keep foreign 
    showm

    Comment


    • #3
      Originally posted by Nick Cox View Post
      Optional varname means that all variables are used by default
      That's it; thanks Nick. I thought that if no variable is specified, then varlist would be empty.

      Comment


      • #4
        The code below works for me.
        Code:
            syntax [varlist(default=none)]
        From help syntax, "default= specifies how the varlist is to be filled in when the varlist is optional and the user does not specify it. The default is to fill it in with all the variables. If default=none is specified, it is left empty."
        I have to admit, it's not my first intuition either.
        Last edited by Jesse Wursten; 25 Nov 2016, 07:45.

        Comment


        • #5
          Jesse: Joseph's title implied that such syntax is problematic, but he did not follow that up in his post. I agree with you: it's not problematic.

          Comment


          • #6
            Originally posted by Jesse Wursten View Post
            From help syntax, "default= specifies how the varlist is to be filled in when the varlist is optional and the user does not specify it. The default is to fill it in with all the variables. If default=none is specified, it is left empty."
            I have to admit, it's not my first intuition either.
            I went back to the help file and saw that after reading Nick's reply, but I didn't get that far in the help file before posting—my apologies to the list.

            Yeah, it would seem more consistent with, say,
            Code:
            local varlist
            to have had the default default as an empty macro, and allow the user to specify something like
            Code:
            syntax [varlist(default=_all)]
            And especially with
            Code:
            syntax [varname]
            it is difficult to imagine that the typical case would be for the user to want all variables in the dataset as the default.

            Comment

            Working...
            X