|
|
||||||||||||||||||
REN_STEM: Rename variablesIf you want to use REN_STEM, feel free to download it here: Download ren_stem.sas If you are not prompted to "Save To Disk", then right-click the link and choose "Save Link Target As..." Otherwise, you will need to save the web page to your computer. Make sure you save the ren_stem.sas file as a plain text file not an
htm/html file.
Disclaimer: There is no warranty on this software either expressed or implied. This program is released under the terms and conditions of GNU General Public License. About REN_STEM
Programmer: Dan Blanchette ()
Center for Entrepreneurship and Innovation Duke University's Fuqua School of Business Durham, NC USA Developed at The Carolina Population Center at The University of North Carolina at Chapel Hill Date: 27Apr2004 Last updated: 25Feb2009 Rename a list of variables by adding a specified prefix or suffix to the variable names
%ren_stem( dataset_name , variable list ,
constant , options );
Description
The REN_STEM SAS macro renames the selected variables by adding the specified prefix or suffix to the
variable name. For example, say you want to have all of your "wave 1" variables start with
"w1_". You could manually type:
rename height = w1_height;
rename weight = w1_weight;
rename income = w1_income;
. . .
Or you could use REN_STEM to do it for you:
ren_stem(myData , _all_ not(id) , w1_ , before); Options
NOTE: The parameters have to be specified in the order of this list.
How to use the REN_STEM macro:
Using the REN_STEM macro requires that you understand how to use the %include statement
and that you know how to call a SAS macro.
%include "LOCATION AND NAME OF A FILE THAT CONTAINS SAS CODE";For example, if you have copied this file to " C:\SASmacros\", then you
tell SAS about this macro by adding the following line to your SAS program:
%include "C:\SASmacros\ren_stem.sas";The include statement makes SAS aware of the REN_STEM macro which is in the file ren_stem.sas. You call the macro
by adding this to your code:
%ren_stem(myData, myvar1 myvar2, pre_ , before); Examples** Make SAS aware of the REN_STEM macro.**; %include "C:\SASmacros\ren_stem.sas"; data new; set old; run; ** now call your macro by feeding whatever variables and whatever you want to tack * on the beginning of the new variable names. A comma separates what you feed * the ren_stem macro. **; *%ren_stem(dataset , list of variables , constant , options) **; %ren_stem( new , x1 x2 x3 x4 x5 y1 , round4_ , before N); ** eg. round4_x1 **; ** or : **; data out.new; set old; run; %ren_stem(out.new , x1 x2 x3 x4 x5 , _max , after sascode n); ** eg. x1_max **; ** or all character variables : **; data new; set old; run; %ren_stem(myData , _numeric_ , _constant , after ); ** all numeric type variables eg. x1_constant **; ** or : ** data new; set old; run; %ren_stem(testdata , x1--gender not(pid) , _min , after); ** eg. x1_min gender_min **; proc contents data= new; run; Back to Main Page Questions or comments? Send them to Dan Blanchette () |