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.   

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 573 views
  • 2 likes
  • 3 in conversation