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

Hi, i have one column named 9-24 . Is there a way to use is in a "keep" statement? I'm new to SAS and all the ways I tried failed as it's considered a range from 9 to 24.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Keep '19-24'n

Wrap each variable you want to keep in a single quote followed by an n.

'VARIABLE'n

View solution in original post

15 REPLIES 15
stat_sas
Ammonite | Level 13

Are you trying to import variable from other source into SAS? Can you please show log?

Thyl
Calcite | Level 5

Just merging 2 datasets.

stat_sas
Ammonite | Level 13

So variable name is 9-24 and this is in SAS dataset?

Thyl
Calcite | Level 5

yes

stat_sas
Ammonite | Level 13

What is the error message? Variable name does not conform to SAS naming conventions.

Thyl
Calcite | Level 5

ERROR 214-322: Variable name 19 is not valid

It was imported from excell.

PGStats
Opal | Level 21

"9-24" is the label of the imported variable. It is not a valid SAS variable name, so it was replaced with "__24" (two underscores). You can use (keep=__24).

PG

PG
stat_sas
Ammonite | Level 13

If you can change variable name in excel then do that. SAS variable name must begin with a letter (A-Z, either uppercase or lowercase) or an underscore (_).

Thyl
Calcite | Level 5

Didn't work. I'm using" options validvarname=any" if that helps

Reeza
Super User

Try 

KEEP '9'n-'24'n.

Thyl
Calcite | Level 5

ERROR: Not all variables from the list '9'n-'24'n have been found

Reeza
Super User

Try double dash instead of single dash. If that doesn't work, please post the results from proc contents on your dataset.

proc contents data=have; run;

Thyl
Calcite | Level 5

Bez tytułu.bmpBez tytułu2.bmp

Reeza
Super User

Keep '19-24'n

Wrap each variable you want to keep in a single quote followed by an n.

'VARIABLE'n

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 15 replies
  • 4004 views
  • 0 likes
  • 5 in conversation