BookmarkSubscribeRSS Feed
jckbnimble
Fluorite | Level 6

Hello all,

 

This seems like an odd questions, but I have imported some data into SAS EG and someof the column names have periods, slashes and parenthesis.

 

For example:

"A. Plasmodesmada"

"Ddimer (Ug/dL)"

 

Normaly, I would assume these are labels in explorer, but it looks like these are also the variable names. They also show up when I do proc contents. I know that SAS vairbales canot have periods or spaces in their names (for obvious reasons) so they must have different names. Any suggestions would be appreciated. 

 

I also tried running a proc contents where I keep the name, but it also shows them with spaces.

 

The import I used was the followng:

 

PROC IMPORT OUT= WORK.RAW
DATAFILE= "C: user/ blah/blah/givemethedataplz/Data_030317.xlsx"
DBMS=xlsx REPLACE ;
GETNAMES=YES;
RUN;

 

Best,

 

Jack

4 REPLIES 4
Kurt_Bremser
Super User

If proc import works under options validvarname=any, such names are possible in SAS. Use 'some funny name'n to adress them in code.

Options validvarname=v7 forces proc import to use names that adhere to SAS naming standards.

jckbnimble
Fluorite | Level 6

I was trying to avoid having to recode a bit of hte variables (which is why I chose GETNAMES = YES or NO). validnames = v7 gives viable names for about 30 of the 100 or so variables, but recodes the rest at Var1-var100. Is it approprate to assume that I am stuck with manually entering in these values?

 

Jack 

Reeza
Super User

Are you using both GETNAMES and the validvarname=v7 option?

 

EDIT: answer to your original question, use proc contents.

proc contents data=raw; run;

 

 

 

 

Tom
Super User Tom
Super User

 

With VALIDVARNAME=ANY both of those work and the names are copied over to the variable NAME, warts and all.  So you will need to use name literals to refer to them by name.  

 

If you use VARLIDVARNAME=V7 then for most values SAS will replace invalid characters with underscores.  But for values like "Ddimer (Ug/dL)" it will use VARx where X is the column number. Not sure if it is the () or the / that SAS doesn't like.  

 

The actual column header value will be stored in the LABEL.  But note that if you happen to have duplicate column names then SAS will append _1, _2, ...  to make them distinct and this will impact both the LABEL and the NAME.

 

 

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
  • 1057 views
  • 0 likes
  • 4 in conversation