BookmarkSubscribeRSS Feed
Howles
Quartz | Level 8
Consider:

[pre]
335 data _null_ ;
336 _all_ = 123 ;
ERROR: Cannot use _all_ as a variable name.
337 _numeric_ = 456 ;
ERROR: Cannot use _numeric_ as a variable name.
338 _character_ = 789 ;
339 run ;
[/pre]

There's no ERROR after line 338. _CHARACTER_ can be used as a variable name (not that this would be a good idea).

Can anyone provide a good reason for the asymmetry with _NUMERIC_ and _ALL_, which trigger errors when used as variable names?

SAS 9.2 2M3 on Win XP.

Thanks.
7 REPLIES 7
data_null__
Jade | Level 19
I cannot answer the question but though this was interesting.

[pre]
2326 data _null_;
2327 _char_ = 1233;
ERROR: Cannot use _char_ as a variable name.
2328 run;
[/pre]
MichelleHomes
Meteorite | Level 14
This is a Special SAS Name List (a type of SAS Variable List) and as such is a reserved word...

Check out doco - http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000695105.htm

Hope this helps,
Michelle
//Contact me to learn how Metacoda software can help keep your SAS platform secure - https://www.metacoda.com
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
To the OP: if you want to pursue this type of anomaly, you will be best served by going directly to SAS Tech Support and opening a track to ask the question, given what you have uncovered.

Scott Barry
SBBWorks, Inc.
Peter_C
Rhodochrosite | Level 12
Michelle
I can understand why _character_ is reserved, but cannot find reference at the link you provided (nor elsewhere) to _char_

Is it just an undocumented alternative to _character_ ?

peterC
data_null__
Jade | Level 19
> Is it just an undocumented alternative to _character_
> ?

I thought _CHAR_was documented but cannot find documentation in relation to SAS Variable List used in data/proc steps.

It would appear to me that the "data step team" at SAS thinks _CHAR_ is "something".

Perhaps _CHARACTER_ is allowed to provide some backward compatibility from days of old.

Further fiddling with _CHARACTER_ produced interesting context sensitive results.

[pre]
2614 options stimer=0 fullstimer=0 missing=.;
2615 data test(keep=_character_);
2616 if 0 then set sashelp.class;
2617 *_char_ = 1233;
2618 _character_ = '9';
2619 cm = cmiss(of _character_);
2620 put _character_;
2621 put (_character_)(=);
2622 put _character_=;
2623 *_numeric_ = '0';
2624 array c
  • _character_;
    2625 put (c
  • ) (=);
    2626 put _all_;
    2627 output;
    2628 stop;
    2629 run;

    9
    Name= Sex= _character_=9
    _character_=9
    Name= Sex= _character_=9
    Name= Sex= Age=. Height=. Weight=. _character_=9 cm=2 _ERROR_=0 _N_=1
    NOTE: The data set WORK.TEST has 1 observations and 3 variables.

    2630 data _null_;
    2631 set test;
    2632 put _all_;
    2633 run;

    Name= Sex= _character_=9 _ERROR_=0 _N_=1
    [/pre]
  • Peter_C
    Rhodochrosite | Level 12
    Stunning

    _char_ is not valid as a var name
    It has the effect of _character_ when used in a keep list
    I found no corresponding abbreviation of _numeric_
    Howles
    Quartz | Level 8
    We don't seem to have a solid explanation, so I guess it's time to put this in front of Tech Support.

    The point is that _CHARACTER_ is *not* reserved, at least not in the way _ALL_ is.

    Also notice that enforcement is more or less limited to the DATA step. Here is a PROC step which is happy to permit use of variable names which are not allowed (or at least discouraged) in the DATA step.

    [pre]
    proc summary data=sashelp.class(obs=3) nway ;
    class sex ;
    output out=badnames(rename = (_freq_ = _n_ _type_=_error_) )
    min(age) = _numeric_
    max(age) = _character_
    mode(age)= _all_
    ;
    run ;
    [/pre]

    Of course referencing these names will be a problem.

    Another slightly interesting bit of evidence. When this code

    [pre]
    proc print ;
    var _numeric_ _character_ _char_ _all_ _notmetoo_ ;
    run ;
    [/pre]

    is placed in the enhanced editor, the first four specs in the VAR statement are recognized and thus colored blue rather than black.

    sas-innovate-2024.png

    Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

    Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

     

    Register now!

    How to Concatenate Values

    Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

    Find more tutorials on the SAS Users YouTube channel.

    Click image to register for webinarClick image to register for webinar

    Classroom Training Available!

    Select SAS Training centers are offering in-person courses. View upcoming courses for:

    View all other training opportunities.

    Discussion stats
    • 7 replies
    • 3256 views
    • 0 likes
    • 5 in conversation