BookmarkSubscribeRSS Feed
Essen5605
Calcite | Level 5

I have a large data set  with a bunch of variables that start with example  2017_Total_65_80P. I am trying to find a way how to use the variable to perform manipulations by not changing the variable name to something like Total_65_80P_2017 since SAS prefers text followed by digit. 

 

NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
24
25 GOPTIONS ACCESSIBLE;
26 data work.CPS_CENSUS_65Plus;
27 set MYLIB.CPS_CENSUS;
28 keep States '2013_Total_65_80';
__________________
22
200
ERROR 22-322: Syntax error, expecting one of the following: a name, -, :, ;, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.

ERROR 200-322: The symbol is not recognized and will be ignored.

3 REPLIES 3
Reeza
Super User

You need to use the n literal notation, quotes and an N after the quotes to indicate this is a name literal and refers to either a variable or data set name. SAS does not allow varialbes to be named with numbers at the start (common in programming languages) and then you need to use this type of notation to get around that limitation. In general, I recommend renaming the variables to Total2017_65_80P. Prefixes are definitely more supported in SAS than suffixes.

Keep States '2013_Total_65_80'n;

If you set the validvarname=V9 it will automatically rename variables when you import them, usually by adding an underscore at the start. 

 


@Essen5605 wrote:

I have a large data set  with a bunch of variables that start with example  2017_Total_65_80P. I am trying to find a way how to use the variable to perform manipulations by not changing the variable name to something like Total_65_80P_2017 since SAS prefers text followed by digit. 

 

NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
24
25 GOPTIONS ACCESSIBLE;
26 data work.CPS_CENSUS_65Plus;
27 set MYLIB.CPS_CENSUS;
28 keep States '2013_Total_65_80';
__________________
22
200
ERROR 22-322: Syntax error, expecting one of the following: a name, -, :, ;, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.

ERROR 200-322: The symbol is not recognized and will be ignored.


 

 

FreelanceReinh
Jade | Level 19

In addition to using the '...'n syntax, you'll need to set

options validvarname=any;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 2155 views
  • 0 likes
  • 3 in conversation