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
How necessary is it to be creative in your work?
How does proc sql work?
what are the types of interactive display types? : Sas-bi
What is the difference between reading data from an external file and reading data from an existing data set?
What system options would you use to help debug a macro? : sas-macro
How are numeric and character missing values represented internally?
What are the statements in proc sql?
why a stop statement is needed for the point= option on a set statement?
How would you define the end of a macro? : sas-macro
What is the basic syntax of a sas program?
what is the basic structure sas administrator? : Sas-administrator
how can you create zero observation dataset? : Sas programming
i have a dataset with 100 obs i want to generate title from 20th obs onwards with total observations. that should contain 100 obs.dont use firstobs and dnt split the data. use dataset block or proc report? how can we genarate;
Are you involved in writing the inferential analysis plan? Tables specfications?
If you were told to create many records from one record, show how you would do this using array and with proc transpose?