How do you add a prefix to some or all variables in a
dataset using a SAS macro?
Answer Posted / kumar
If it is Interview Question I would do say something like this.
/* Running the renaming macro */
options macrogen mprint mlogic;
%macro rename(lib,dsn);
options pageno=1 nodate;
proc contents data=&lib..&dsn;
title "Before Renaming All Variables";
run;
proc sql noprint;
select nvar into :num_vars
from dictionary.tables
where libname="&LIB" and
memname="&DSN";
select distinct(name) into :var1-
:var%TRIM(%LEFT(&num_vars))
from dictionary.columns
where libname="&LIB" and
memname="&DSN";
quit;
run;
proc datasets library=&LIB;
modify &DSN;
rename
%do i=1 %to &num_vars;
&&var&i=NEWNAME_&&var&i.
%end;
;
quit;
run;
options pageno=1 nodate;
proc contents data=&lib..&dsn;
title "After Renaming All Variables";
run;
%mend rename;
| Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
for report generation which one you used proc report or data_null_?
what is sas and what are the functions? : Sas-administrator
what is sas application server? : Sas-di
What are the data types in sas?
Mention the validation tools used in SAS?
Hi all, If Anybody has Advance SAS Certification dumps??? Please share with me. Email: pramod.kalugade03@gmail.com
what is the use of proc sql? : Sas programming
explain the use of % includes a statement in sas? : Sas-administrator
what are the new features included in the new version of sas i.e., Sas 9.1.3? : Sas programming
How to sort in descending order?
How would you identify a macro variable?
what are the types of interactive display types? : Sas-bi
explain the main difference between the nodup and nodupkey options? : Sas-administrator
Define run-group processing?
What do you know about sas and what we do? : sas-grid-administration