×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Input data into an array

Input data into an array

Input data into an array

(OP)
hello, does anyone know how i can input data from specific columns in a data file to an array? Thank you.

example - infile 'c:\data.dat';
          input dataset1 17-33;

i need the variable dataset1 to be read into an array?

i hope this makes sense.

RE: Input data into an array

Will just copy from the doc I gave to my people

Reading into an array
 INFILE INFIL;                   <== FILE ON JCL CARD
  INPUT @9  (DESC1-DESC5)($CHAR20.)

 THE ABOVE WILL READ IN 5 OCCURANCES OF DESC

-----
 INFILE INFIL;                   <== FILE ON JCL CARD
  ARRAY NUMBERS{10};             <== DEFINE SIZE OF ARRAY
  INPUT @30  VAR1     $CHAR9.
        @319 NUMBERS(*) IB2.0     /* 20 CHARACTERS OF FIXED BIN 15 */
        @830 VAR3     $CHAR170. @;

 THE ABOVE WILL READ IN 10 OCCURANCES OF NUMBERS INTO THE ARRAY

 NOTE CURLY BRACKETS

 ALSO NOTE THAT IN ANY SUBSEQUENT DATA STEPS THAT THE 'ARRAY DEFINITION'
   NEEDS TO BE REDONE FOR EACH DATA STEP --- I DONT LIKE IT EITHER
-----

DO I = 1 TO DIM(NUMBERS);
   IF NUMBERS{I} > 13 THEN NUMBERS{I} = 0;
END;
 NOTE NO CURLY BRACKETS ON DIM STATEMENT

----

This help?

RE: Input data into an array

(OP)
Hello,
Thank you very much, I will try that. If i don't know the size of the array do i just use the ubound(array) syntax, is that correct? If you don't mind, can you show me an example of that. Thanks again.

RE: Input data into an array

When you define the array you define it like this
ARRAY JUNK{*} JUNK1 JUNK2 JUNK3;

I have never used an * when reading in - I always define a set space and have an error produced if it gets passed (your mileage may vary)

after that it gets more interesting.  You can use the functions LBOUND, HBOUND and DIM

ex. Do I = LBOUND(Junk) to HBOUND(Junk)
or
Do I = 1 to DIM(Junk)

arrays are fun, but like in any other language if you right past what you have defined as the 'space' you can overwrite things and get unexpected errors.  Don't forget that you have to define the array in each data step where you plan on using it (and on occasion you will need to RETAIN the whole array - for example I wanted to output 1 record with the info from twelve months - first time through I only got December... I had left off the retain of the array, so SAS zerod it out for each new observation).

Good luck

RE: Input data into an array

(OP)
Wow, thank you very much, you've helped me a great deal. Array's definitely are fun and very powerful too, they can make life real easy if coded properly Thanks again.

RE: Input data into an array

one more weird thing.  SAS really stores the arrasy as seperate variables (so if I defined an array as WEIGHT{10} I would have WEIGHT1 WEIGHT2 WEIGHT3 WEIGHT4 WEIGHT5 WEIGHT6 WEIGHT7 WEIGHT8 WEIGHT9 WEIGHT10).  I always found it a bit annoying that I did not get WEIGHT01 to WEIGHT10 so your deletes and things like that can be coded as WEIGHT1-WEIGHT10

more my own pet peeve than anything

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close