TomaHawKPT
Programmer
Greetings,
I'm new to SAS, and I'm having trouble adding a new variable (or column) to a dataset (or table). This new column results from a macro that receives as a parameter an existing variable of that dataset.
Below is a simplified example of what I need to do, but I can't figure how to do it.
/* I have a dataset with a column (col1) which value must me passed to the macro */
DATA numbers;
INPUT col1;
DATALINES;
1
2
3
4
5
run;
/* Just an example of a macro */
%macro double(var);
%let doubled = var * 2;
&doubled; * returns the double;
%mend;
/* Now I'd like to add a new column to the data that results from the macro. I'd like to do something like this: */
data doubles
set number;
col2=%double(col1);
run;
/* OR */
proc sql;
create doubles as
select col1, %double(col1) as col2
from numbers;
quit;
Thanks,
Nuno Vidal
I'm new to SAS, and I'm having trouble adding a new variable (or column) to a dataset (or table). This new column results from a macro that receives as a parameter an existing variable of that dataset.
Below is a simplified example of what I need to do, but I can't figure how to do it.
/* I have a dataset with a column (col1) which value must me passed to the macro */
DATA numbers;
INPUT col1;
DATALINES;
1
2
3
4
5
run;
/* Just an example of a macro */
%macro double(var);
%let doubled = var * 2;
&doubled; * returns the double;
%mend;
/* Now I'd like to add a new column to the data that results from the macro. I'd like to do something like this: */
data doubles
set number;
col2=%double(col1);
run;
/* OR */
proc sql;
create doubles as
select col1, %double(col1) as col2
from numbers;
quit;
Thanks,
Nuno Vidal