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 interleaving in SAS?

673


what is data integration? : Sas-di

612


is data integration and etl programming is same? : Sas-di

576


Can you suggest us materials for sdtm mapping?

4039


how do you want missing values handled? : Sas programming

534






How do you specify the number of iterations and specific condition within a single do loop?

621


How would you identify a macro variable?

650


explain the function of substr in sas? : Sas-administrator

556


i want for interview question & answer plz it need immediate send t my mail raviprakashmot@gmal.cm

1845


what is business intelligence? : Sas-bi

583


Are you sensitive to code walk-throughs peer review or QC review?

2607


Hi Friends, Am Priya,new to your forum. am looking for Interview questions on SAS Platform Administration. I searched everywhere but I couldn't find them,please can anyone help me with complete interview questions normally everyone will face in the interviews on SAS Administration. am really facing problems in the interviews,am not able to answer any of their questions. I would really appreciate all your help if you can email the complete Interview Questions to priyafeb84@gmail.com Kindly awaiting for your reply with eager

1612


what is proc Index? and what is proc document?

1996


what are the scrubbing procedures in sas? : Sas programming

831


Hi all, If Anybody has Advance SAS Certification dumps??? Please share with me. Email: pramod.kalugade03@gmail.com

1582