BookmarkSubscribeRSS Feed
David_S
Fluorite | Level 6

Hello,

How do you use ARRAY (using a loop) to accomplish the following:

student_id     fund1     fund2     fund3     fund4     fund5     fund6     fund7              

120101          1101                                                                     

120102          1011     1190     1228

120103          1130

120104          1040     1125     1186     1124     1085     1044     1091    

120105          1053     1220     1185     1112     1056     1199     1183

to reflect an output as such:

student_id     i          fund_code

    

120101          1     1101

120102          1     1011

120102          2     1190

120102          3     1228

120105          1     1130

etc. etc.

Thank you for your assistance.

5 REPLIES 5
Tom
Super User Tom
Super User

data want ;

  set have ;

  array fund fund1-fund7;

  do i=1 to dim(fund);

    fund_code = fund(i);

       if not missing(fund_code) then output;

  end;

  drop fund1-fund7 ;

run;

art297
Opal | Level 21

Basically the same suggested code as Tom's, but you can use a wild card to define the variables going into the array:

data want (keep=student_id i fund_code);

  set have;

  array funds(*) fund:;

  do i=1 to dim(funds);

    if not missing(funds(i)) then do;

      fund_code=funds(i);

      output;

    end;

  end;

run;

David_S
Fluorite | Level 6

Tom and Arthur,

Thank you very much.  I got wrapped around an array with a DO UNTIL loop but I was also struggling with the ability to do what you illustrated above, "funds(i)."  This will help me move forward.

Based on other posts it appears that I can say you (Tom and Arthur) are pretty well versed in SAS programming language.  This may not be the best venue to ask but I'll do it anyway, assuming you've taken the Base SAS Certification, what are the best resource to prepare for this cert?

Thank you all,

David

art297
Opal | Level 21

David,

I'd ask that question as a new discussion so that you can get feedback from everyone on the forum.

I've been using SAS for over 40 years, but never bothered to take any of the certification exams. That isn't to say that it isn't useful but, after my PhD, I swore off any and all additional tests and certifications.

Art

David_S
Fluorite | Level 6

LOL.  Thanks Arthur.

David

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 1301 views
  • 7 likes
  • 3 in conversation