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

Mention sas system options to debug sas macros.

1163


What is the use of divide function?

1055


What are the data types does SAS contain?

1103


How can I remove header from output data set?

2613


Difference between nodup and nodupkey options?

1181


what is the use of sas management console? : Sas-di

1083


What are the functions used for character handling?

1242


Explain bmdp procedure?

1024


How would you code a merge that will write the matches of both to one data set, the non-matches from the left-most data?

1085


What is the basic syntax of a sas program?

1186


what is the use of proc sql? : Sas programming

1123


How is character variable converted into numeric variable and vice versa?

1162


What is the different between functions and PROCs that calculate the same simple descriptive statistics?

1776


How do you delete duplicate observations in sas?

1060


What are SAS/ACCESS and SAS/CONNECT?

1137