03-28-2017 02:29 PM
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.
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 ;
03-28-2017 02:39 PM
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.
03-28-2017 02:57 PM
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?
03-28-2017 03:29 PM - edited 03-28-2017 03:30 PM
Are you using both GETNAMES and the validvarname=v7 option?
EDIT: answer to your original question, use proc contents.
proc contents data=raw; run;
03-28-2017 04:47 PM
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.