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


Please Help Members By Posting Answers For Below Questions

what is sas application server, database server, sas olap server and sas metadata server? : Sas-di

549


What are the data types in sas?

599


How to read an input file in sas?

647


What is the SAS data set?

669


What is the command used to find missing values?

584






What is the difference between reading data from an external file and reading data from an existing data set?

630


describe about physical data integration? : Sas-di

555


If a variable contains only numbers, can it be a character data type?

606


What do you code to create a macro? : sas-macro

566


What do the PUT and INPUT functions do?

769


What are symget and symput? : sas-macro

722


explain the main difference between the nodup and nodupkey options? : Sas-administrator

678


What is the order of application for output data set options, input data set options and SAS statements?

1076


how do you test for missing values? : Sas programming

577


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

3051