BookmarkSubscribeRSS Feed
Matt3
Quartz | Level 8

Hello,

 

I would be greatefull if anyone could help me with ':' in variable name.  When I import from excel files I ve got var names like 'Data var: id'n while I can manage(drop, keep, rename) with names without ':' exemple  'Data var name'n, I can`t do anything with first one.

 

Thank you.

 

 

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Unfortunately your a bit stuck.  : means any variable with a prefix of.  However this is not generally the case with Excel.  Let me explain, first Excel is a really poor data medium.  As you are finding, there is no real rules on what goes into a spreadsheet, so you "varaible" names could be anything, even pictures.  Now for SAS to try to work with this mess, they give you the option of referring to variables (we will call it that, but in Excel terms it is the first cells contents) using named literals, or, look for this text in the box.  Behind the scenes SAS creates a SAS compliant name for it by stripping spaces, special characters and fixing length.

Simple solution, don't use Excel - it really does cause so many problems.

More difficult solution, either know the names and put them in by hand, or use a bit of code to get the variable names, and then work with that - be prepared for your code to fail at each run as Excel "names" change though.

E.g.

proc sql;
  select NAME
  into   :VLIST separated by ' '
  from   SASHELP.VCOLUMN
  where  LIBNAME="YOURLIB"
     and MEMNAME="YOURDS";
quit;

* Use
data want;
set yourlib.yourds (keep=&vlist.);
run;
Ksharp
Super User

use the following option to get legal variable name of SAS.

 

options validvarname=v7 ;
proc import ............
ChrisBrooks
Ammonite | Level 13

Options validvarname=any should work here - but I agree, change it to a "normal" SAS name ASAP e.g.

 

options validvarname=any;

data test(rename=("Data Var:id"n=DataVarid));
	set sashelp.class;
	"Data Var:id"n=1;;
run;
Reeza
Super User

If you set the OPTION VALIDVARNAME=V7 before you import the data, SAS will automatically convert the variable name to a valid SAS name and keep the name as a label. 

 

You can then rename it if you want and I suspect that's really the easiest fix.

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
  • 805 views
  • 3 likes
  • 5 in conversation