DATA Deposits;
input Acctno type $ Balance;
cards;
1 Demand 10
2 Time 20
3 Demand 10
4 Saving 30
5 Demand 10
6 Saving 30
7 Time 20
8 Saving 30
9 Demand 10
;
Run;
%let Diff_DD = 1;
%let Diff_SD = 2;
%let Diff_TD = 3;
I need o add Diff_DD value to the "1 Demand 10"
Diff_TD value to the "2 Time 20"
Diff_SD value to the "4 Saving 30"
Please help
"Add" to what? Do you need a new variable? Please post the dataset you want to create.
Do you want to concatenate the macro variable value to concatenation of other 3 variables ?
Declare the macro variables first, then add the difference variable in the same DATA step:
%let Diff_DD = 1;
%let Diff_SD = 2;
%let Diff_TD = 3;
data deposits;
input acctno type $ balance;
select (acctno);
when (1) difference = &Diff_DD;
when (2) difference = &Diff_SD;
when (4) difference = &Diff_TD;
otherwise;
end;
cards;
{etc}
;
run;
Guys Thank you for you reviews in this issue, I was in vacation so sorry for late reply.
@ andreas_lds , I need to add the difference to each account for example The new data set must look like as bellow
1 Demand 11
2 Time 20
3 Demand 10
4 Saving 32
5 Demand 10
6 Saving 30
7 Time 23
8 Saving 30
9 Demand 10
;
Run;
@ rajat.sas you may now understand what actually is the requirement.
Thank you guys, I appreciate your effort to help..
looking Forward
Why are the values only added some of the time? We can see that you want to sum with the three additional values for demand, time and saving, but you haven't given any clue as to why you are only doing it with certain records.
If you want to apply these changes on every observation, you can do it with one additional statement:
balance = balance + &DIFF_DD * (type='Demand') + &DIFF_SD * (type='Saving') + &DIFF_TD * (type='Time');
As others have noted, your intention isn't 100% clear, even based on your revised posting. Why is &DIFF_TD added to "7 TIme 23" but not to "2 Time 20" ? Based on your answer, there will likely be further coding necessary. It won't be difficult, but it will require a clear understanding of what you are trying to achieve.
Good luck.
OniMoni, indeed answering Art Tabachneck's question would clear things up.
In the meantime, here is an ever shorter form of Astounding's solution, even making the macro variable unnecessary:
balance = balance + (whichc(type, 'Demand', 'Saving', 'Time'));
Cheers.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.