12-08-2014 03:19 AM
Am reading data from excel sheet, in that i dont know how many colums are there.
I want to place * after 3 characters of every column name.
sample column names of excel sheet:
Desired output column names:
12-08-2014 04:31 AM
Having an asterix (*) in a dataset is not valid. So you will not be able to do what you want there.
Also, if your data is in Excel, then I would strongly suggest you save to CSV, then write the import program yourself using datastep/infile/input statements. You can then set labels, names formats etc. and have control over your import rather than letting proc import guess for you. You still wont be able to use asterixs in the variable name however.
12-08-2014 04:54 AM
Well, way I would do it is:
set sashelp.vcolumn (where=(libname="SASHELP" and memname="CLASS")) end=last;
if _n_=1 then call execute('data want; set sashelp.class (rename=(');
call execute(' '||strip(name)||'='||substr(name,1,3)||'_hello_'||strip(substr(name,4)));
if last then call execute(')); run;');
You could also do it in SQL, i.e. select into macro variable, then use that macro variable as your rename.
12-08-2014 05:25 AM
That's simply a very bad idea as such names are not valid SAS names SAS(R) 9.4 Language Reference: Concepts, Fourth Edition. It could be done but then you would have to reference all your SAS variables in all your code as SAS name literals in the form: 'cus*tomer ID'n.
For such requirements use variable labels instead. SAS Procedures creating reports allow you to use the variable labels instead of the variable names for "printed" output.
The other question you're having is: How can I change variable names and variable attributes in a SAS data set using code (=automated)? This is a question which came up already many times in this forum and I suggest you do a search.