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 interleaving in SAS?
what is data integration? : Sas-di
is data integration and etl programming is same? : Sas-di
Can you suggest us materials for sdtm mapping?
how do you want missing values handled? : Sas programming
How do you specify the number of iterations and specific condition within a single do loop?
How would you identify a macro variable?
explain the function of substr in sas? : Sas-administrator
i want for interview question & answer plz it need immediate send t my mail raviprakashmot@gmal.cm
what is business intelligence? : Sas-bi
Are you sensitive to code walk-throughs peer review or QC review?
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
what is proc Index? and what is proc document?
what are the scrubbing procedures in sas? : Sas programming
Hi all, If Anybody has Advance SAS Certification dumps??? Please share with me. Email: pramod.kalugade03@gmail.com