BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jonthiele
Fluorite | Level 6

I have a large number of records in a file where each record contain 100 fields - all 5 numeric characters in length.   I need to process each value in the record.  I can define the fields and process them with statements like:

 

data file1 ;

infile testfile ;

   input @1 field1 5.

           @6 field2 5.

           @11 field3 5.

...

           @496 field100 5. ;

 

   if field1 = /*   some condition   */  do;

     /*   some processing   */

   end ;

   if field2 = /*   some condition   */  do;

     /*   some processing   */

   end ;

,,,

   if field100 = /*   some condition   */  do;

     /*   some processing   */

   end ;

 

I'm sure there is some much easier way of doing this with an array but I just can't seem to find it in any documentation that I have read.   Any help would be appreciated.  

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Like this?

  array F[*] FIELD1-FIELD100; 
  input (FIELD1-FIELD100) (5.);
  do I=1 to 100;
    if F[I]= /*   some condition   */  do;
      /*   some processing   */
    end ;
  end;


 

View solution in original post

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

Like this?

  array F[*] FIELD1-FIELD100; 
  input (FIELD1-FIELD100) (5.);
  do I=1 to 100;
    if F[I]= /*   some condition   */  do;
      /*   some processing   */
    end ;
  end;


 

jonthiele
Fluorite | Level 6

Yes - this is exactly what I was looking for - simple, elegant and works perfectly.

 

Thank-you.  

SASKiwi
PROC Star
array fields (*) field1 - field100;
do i = 1 to dim(fields);
  fields(i) < some statement >;
end;
jonthiele
Fluorite | Level 6

 

Thank you for this.   

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1205 views
  • 2 likes
  • 3 in conversation