Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Which command is used to save logs in the external file?

1024


what are sas/access and sas/connect? : Sas programming

938


What would be the result of the following SAS function (given that 31 Dec, 2000 is Sunday)?

1096


I have a dataset concat having variable a b & c. How to rename a b to e & f?

959


State the difference between INFORMAT and FORMAT ?

1036


explain about sas business intelligence? : Sas-bi

1070


What is the difference between proportion and average?

3263


How do dates work in SAS data?

1115


how can you put a "trace" in your program? : Sas programming

1001


How will you react when, while consulting a SAS documentation manual to get an answer to a problem, someone says hey, I thought you were supposed to know all that stuff already, and not have to look it up in a book?

2398


how does sas handle missing values in a merge? : Sas programming

980


What is the difference between nodupkey and nodup options?

969


what are the benefits of data integration? : Sas-di

1022


what are the component of range? : Sas-bi

1016


To what type of programms have you used scratch macros?

2523