I imported a table from Excel. The variable name is "a2-4". How to deal with these names?
Thanks
Setting the SAS option VALIDVARNAME to V7 will automatically translate variable names to valid SAS names. So a2-4 will be renamed to a2_4. This is actually a good practice to follow as it avoids having to reference non-valid SAS variable names as @Patrick describes: 'a2-4'n
Depending on how you import there might be options available for SAS to translate source column names into valid SAS variable names.
If it's not a valid name then you must quote it as a SAS name literal when you use the column in code as done below:
'a2-4'n = 5;
Setting the SAS option VALIDVARNAME to V7 will automatically translate variable names to valid SAS names. So a2-4 will be renamed to a2_4. This is actually a good practice to follow as it avoids having to reference non-valid SAS variable names as @Patrick describes: 'a2-4'n
Use the "name literal" as suggested by @Patrick to immediately rename them to valid SAS names (like a2_4).
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →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.