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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.