BookmarkSubscribeRSS Feed
David_S
Fluorite | Level 6

Hello,

I'm attempting to accumulate/sum the amounts associated with all the "Athletic" fund_types.  However, my loop essentially ends at first iteration.  What am I missing (see code below)?

student_id  Fund_Type1     Fund_Type2     Fund_Type3 Fund_Type4  Fund_Type5 Fund_Type6  Fund_Type7     Fund_Type8     Fund_Type9  amount1........................................................................amount10  j   k     Athletic

120102FoundationsSkillsetAthletic 22501500500.......311500
120103Athletic 1500.........1111500
120104MilitaryAthleticCorporateAthleticWorkFoundationsFoundations 1500150037504500475052503750...2111500
120104MilitaryAthleticCorporateAthleticWorkFoundationsFoundations 1500150037504500475052503750...4114500
120106TalentFoundationsAthleticLoanAthleticSkillset 375050027505007505000....3112750
120106TalentFoundationsAthleticLoanAthleticSkillset 375050027505007505000....511750
120111LoanCorporateState GrantAthleticFoundationsMilitaryReligiousFoundations 2250525027501750175047502250500..4111750
120112InternalAcademicReligiousLoanMilitaryFoundationsAthletic 1750475030001000525015001500...7111500
120116AcademicCorporateAthleticInternalCorporateCorporateAcademicFoundationsReligious 5001000175035004250250525042505000.3111750
120119MilitaryAthleticAcademicMilitary 3750375050001750......2113750

Data Work.types_aid_merged;

merge schol_types_rot

     Sasuser.Student_aid;
by student_id;

array fund_type{*} fund_type:;

array amount{*} amount:;

     do j=1 to dim(fund_type);

          if fund_type{j}="Athletic" then do;

               do k=1 to dim(amount);

               Athletic=0;

               Athletic+amount{j};

          end;

          output;

     end;

end;

RUN;

Thank you,

David

7 REPLIES 7
Kurt_Bremser
Super User

I don't find a reference for your variable_name: notation in the SAS array documentation. Use fund_type1-fund_type9 and amount1-amount9 instead.

[Update]

The notation works fine.

But:

Write your programs so that corresponding do and end statements line up on the same column.

I also find that

Athletic=0;

Athletic+amount{j};

give the same result as

Athletic=amount{j};

!!

Astounding
PROC Star

In terms of your original program, this likely means that you should move the statement:

Athletic=0;

It probably belongs one line above, before looping with K.

David_S
Fluorite | Level 6

Kurt,

Oh yeah, I am missing a reference.  Thank you both for your assistance.  Much appreciated!

David

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,


Well, if you data was normalized e.g.:

STUDENT_ID     FUND_TYPE     AMOUNT

120012               Athletic               123

120012               Military                567

...

It would be a simple sum() where FUND_TYPE="Athletic"...

David_S
Fluorite | Level 6

Correct, I gave that a try as well.

art297
Opal | Level 21

David,

I would try something like the following. My data have is using the file resulting from your merge:

data want;

  set have;

  array fund_type{*} fund_type:;

  array amount{*} amount:;

  Athletic=0;

  do j=1 to dim(fund_type);

    if fund_type{j}="Athletic" then Athletic+amount{j};

  end;

run;

David_S
Fluorite | Level 6

Oooh, I like this approach better Art; and, it ignores missing values.

Thanks again,

David

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2487 views
  • 0 likes
  • 5 in conversation