BookmarkSubscribeRSS Feed
OniMoni
Calcite | Level 5

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

7 REPLIES 7
andreas_lds
Jade | Level 19

"Add" to what? Do you need a new variable? Please post the dataset you want to create.

rajat_sas
Calcite | Level 5

Do you want to concatenate the macro variable value to concatenation of other 3 variables ?

tish
Calcite | Level 5

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;

OniMoni
Calcite | Level 5

Guys Thank you for you reviews in this issue, I was in vacation so sorry for late reply.

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;

@

art297
Opal | Level 21

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.

Astounding
PROC Star

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.

joehinson
Calcite | Level 5

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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1417 views
  • 0 likes
  • 7 in conversation