Hi,
Thanks for the response. Below is a brief program for what I am trying to do.
data dict;
input var $ type $ length 2. varnum 2.;
datalines;
name char 10 1
dept char 10 2
age num 2 3
sex char 1 4
graduated char 1 5
;
data have;
input var1 $ var2 $ var3 2. var4 $ var5 $;
datalines;
John Sales 30 M Y
Mary Acctng 40 F N
;
%macro format;
proc sql noprint;
select var, type, length, varnum
into :mvar1- , :mtype1-, :mlength1-, :mvarnum1-
from dict;
%let count = &sqlobs;
quit;
data temp;
set have;
%do v = 1 %to &count;
rename var&v = &&&mvar&v;
%end; /* end generate variable type conversion */
run;
data want;
set temp;
if graduate = "Y" then school = "college";
run;
%mend;
%format;
I idea is that I have a data dictionary that includes metadata for the variables represented in a dataset. I use this data dictionary to manipulate the dataset (eg. rename variables, change data types, set variable lengths, etc.). In the example I added the if/then statement (if graduate = "Y" then school = "college") creating a new variable named "school". What I want to do is have this variable created from a data dictionary in the macro instead of me adding an if/then statement to create it. I have tried to add the if/then statement to the data dictionary and that works but I wonder if there is a cleaner way to do it.
The endgame for this idea is to have a data dictionary that I can add variables to the will get added to the dataset whenever the macro runs instead of adding if/then statements.
Hope that helps. Thanks.