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.
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;
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;
Yes - this is exactly what I was looking for - simple, elegant and works perfectly.
Thank-you.
array fields (*) field1 - field100;
do i = 1 to dim(fields);
fields(i) < some statement >;
end;
Thank you for this.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: