DATA Step, Macro, Functions and more

Finding the actual name of a variable

Reply
Occasional Contributor
Posts: 7

Finding the actual name of a variable

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

Super User
Posts: 7,761

Re: Finding the actual name of a variable

Posted in reply to jckbnimble

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 7

Re: Finding the actual name of a variable

Posted in reply to KurtBremser

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 

Super User
Posts: 19,770

Re: Finding the actual name of a variable

[ Edited ]
Posted in reply to jckbnimble

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

 

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

proc contents data=raw; run;

 

 

 

 

Super User
Super User
Posts: 7,039

Re: Finding the actual name of a variable

Posted in reply to jckbnimble

 

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.

 

 

Ask a Question
Discussion stats
  • 4 replies
  • 142 views
  • 0 likes
  • 4 in conversation