Help using Base SAS procedures

Using ARRAY

Reply
Occasional Contributor
Posts: 16

Using ARRAY

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.

Super User
Super User
Posts: 6,502

Re: Using ARRAY

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;

PROC Star
Posts: 7,364

Re: Using ARRAY

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;

Occasional Contributor
Posts: 16

Re: Using ARRAY

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

PROC Star
Posts: 7,364

Re: Using ARRAY

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

Occasional Contributor
Posts: 16

Re: Using ARRAY

LOL.  Thanks Arthur.

David

Ask a Question
Discussion stats
  • 5 replies
  • 229 views
  • 6 likes
  • 3 in conversation