02-01-2013 01:33 PM
i have more than one dataset in the sas which has more than 1000 variables. all these variables are specific code (eg: 1234,6789, 4343, ect). I have once excelsheet which mentioned all these code (eg: 1234,6789, 4343, ect) along with variable explanation (eg: 1234=total_population).
my question is what is the best practice to implement that excel sheet into the sas dataset so that it rename 1234=total_population and with all other code to particular name?
02-01-2013 01:52 PM
When you do a proc contents on your SAS data set what are the names of your variables? (are they really 235,6789?)
I thought SAS doesn't allow for column names to be just digits:smileyconfused:
02-01-2013 02:13 PM
02-01-2013 02:15 PM
Arthur Tabachneck wrote:
Anca tilea: Actually it does if you have the validvarname option set to ANY, but I wouldn't recommend doing that.
sandip patel: It would help if you tell us more and provide a brief example (i.e., NOT with 1,000 variables)
Here is a non SAS question: how do I reference someone in my reply (like you just did)??
02-01-2013 03:05 PM
If its in an excel sheet I typically create a new column in excel using functions that looks like this:
And then copy and paste that into SAS code with the rename statement.
So I add a rename before the names and a semi colon afterwards.
There are more automated solutions but this works as well.
02-01-2013 03:17 PM
I would say that best practice (in most scenarios) is not to have tables with hundred/thousands of columns. I quite positive it will be easier for you if you transpose your data, and then you can use standard table lookup techniques, like joins, merge, user defined formats etc to apply descriptions to your codes.
02-04-2013 11:25 AM
@Arthur - sir, i have variable like
and many more lwith this kind of code - wanted to change to
i have excel sheet with code (P002001) and actual variable name (tot_urban_rural) that i wants to rename it...
Thanks all for your feedback
02-04-2013 11:31 AM
You rename variables in SAS using either proc datasets or in a data step.
In a datastep you are creating new data set whereas in proc datasets you're modifying your original dataset. Generally how you get variables listed is the issue. If you only need to do it once then typing it in, or copying it from excel is fine. If you need to do it multiple times, then I agree with Linus, the structure of your data is not optimal. However, you can do it using macro variables. It's been illustrated many times on this forum so some searching should help you find it.
In a dataset:
In proc datasets:
proc datasets library=work;
02-04-2013 12:13 PM
informat name $32.;
input var $ name;
proc sql noprint;
into :renames separated by " "
input p002001 p002002 p002003 p002004;
1 2 3 4
5 6 7 8
proc datasets library=work;