BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AllSoEasy
Obsidian | Level 7

Hello,

I know it is possible to name a variable with a dash as: "variable-name"

But when the dash is followed by a number I am having issues, i.e.: "beta3_-1"

This is not being recognized as a variable although it is the name of a column in my dataset, using single quotes is not working. Could anyone give me a suggestion on how I can reference this variable please? I'm sure it's a simple thing, I don't mean to waste anyone's time but I haven't been able to find a simple answer.

Thanks a lot,

-Ryan

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

By default, in Base SAS, you can't name a variable with a -.  You can label a variable with dashes though.

Or you can set options validvarname=any;

And then name them however you want. But then you ahve to refer to them as "beta3_-1" instead of beta3_1.

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

A dash is NOT allowed in a variable name unless you have the option validvarname=any set.

Reeza
Super User

By default, in Base SAS, you can't name a variable with a -.  You can label a variable with dashes though.

Or you can set options validvarname=any;

And then name them however you want. But then you ahve to refer to them as "beta3_-1" instead of beta3_1.

AllSoEasy
Obsidian | Level 7

Thanks a lot guys, simple enough.

Ron_MacroMaven
Lapis Lazuli | Level 10

you can use the quoted-string qualifier N

after a variable name that contains special characters:

options validvarname=any;

data _null_;

attrib "var-A"n        length = 8

       'var B'n        length = 8

       'var! Really?'n length = 8;

array Whiz(*) _numeric_;

do I = 1 to dim(Whiz);

   Whiz(I) = I**I;

   end;

  put (_all_) (=);

run;

'var-A'n=1 'var B'n=4 'var! Really?'n=27 I=4

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 2763 views
  • 3 likes
  • 4 in conversation