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
what is sas application server, database server, sas olap server and sas metadata server? : Sas-di
What are the data types in sas?
How to read an input file in sas?
What is the SAS data set?
What is the command used to find missing values?
What is the difference between reading data from an external file and reading data from an existing data set?
describe about physical data integration? : Sas-di
If a variable contains only numbers, can it be a character data type?
What do you code to create a macro? : sas-macro
What do the PUT and INPUT functions do?
What are symget and symput? : sas-macro
explain the main difference between the nodup and nodupkey options? : Sas-administrator
What is the order of application for output data set options, input data set options and SAS statements?
how do you test for missing values? : Sas programming
Hi Jeevan/Akshara I have tried to contact SASI Vats for latest Advanced SAS Programming Certification Dumps (A00-212) but have not got any response. I would highly and gratefully appreciate your assistance in this regard. If you guys have access to this, would you be kind enough to forward it to me ? I would abide by all the terms you have for this. Please, note my email id: upretigopi@yahoo.com Preti Sharma