Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tech Tip: Use SQL and DATASETS procedures to rename variables

Similar presentations


Presentation on theme: "Tech Tip: Use SQL and DATASETS procedures to rename variables"— Presentation transcript:

1 Tech Tip: Use SQL and DATASETS procedures to rename variables
Rebecca Willison Analytical Scientist Monsanto

2 The scenario A solution
You need to add a prefix or suffix to some or all of the variables in a dataset The number and/or names of the variables may change each time you run your program A solution Use PROC SQL to create a macro variable with a statement to rename variables Use PROC DATASETS (or DATA step) to rename variables

3 Example Code Create rename statement of the form var1=newvar1
proc sql noprint; select cats(name,'=','new',name) into :newnames separated by ' ' from dictionary.columns where libname="WORK" and memname="MYDATA" and name not like "id"; quit; proc datasets library=work nolist; modify mydata; rename &newnames; run; Store list of all variables to be renamed in macro variable newnames Specify your dataset and the variables you want to exclude from renaming Use the macro variable newnames to rename your variables Note: You can also use the “newnames” macro variable in a data step to rename variables, however this is less efficient as each row of data is being read in.

4 Any Questions? Create rename statement of the form var1=newvar1
proc sql noprint; select cats(name,'=','new',name) into :newnames separated by ' ' from dictionary.columns where libname="WORK" and memname="MYDATA" and name not like "id"; quit; proc datasets library=work nolist; modify mydata; rename &newnames; run; Store list of all variables to be renamed in macro variable newnames Specify your dataset and the variables you want to exclude from renaming Use the macro variable newnames to rename your variables Note: You can also use the “newnames” macro variable in a data step to rename variables, however this is less efficient as each row of data is being read in.


Download ppt "Tech Tip: Use SQL and DATASETS procedures to rename variables"

Similar presentations


Ads by Google