02-03-2015 04:18 PM
I'm trying to assign a value to 40 variables in a data set using if then statement in MACRO. But When I execute it, it assigns value to only last variable in the macro list. Here is my code.
%macro up (var, var2);
if &var is <0 then &var2= -1;
else if &var is >0 then &var2 = 1;
%up (expense_1, crd_1);
%up (expense_2, crd_2);
%up (expense_40, crd_40);
when I execute this code my data set only contains crd_40. I don't see crd_1 thru crd_39.
02-03-2015 04:23 PM
From what I can see you are overwriting ABC_NEW each time. You would need the MODIFY statement to APPEND as written.
However perhaps you can do it ALL in one simple data set. Show example input data and example of what you want.
02-03-2015 04:32 PM
This is my Input data
And this is what I want
02-03-2015 04:42 PM
SIGN function and ARRAY.
02-03-2015 04:58 PM
Thank You for the piece of code. This is helpful, but the variables Expense1, expense_2.... are actually named different. Like car_expense, book_expense, exp_office, exp_gas and so on. I named it as Expense_1...expense_40 just for example code.
02-03-2015 04:30 PM
Your IF statements are incorrect assuming that is your actual code, you have an IS word that doesn't belong there.
if &var <0 then &var2= -1;
else if &var>0 then &var2 = 1;
This also seems perfect for arrays rather than macros.
Need further help from the community? Please ask a new question.