+ Reply to Thread
Results 1 to 2 of 2

Thread: Not sure how to read this data in

  1. #1
    Points: 1,059, Level: 17
    Level completed: 59%, Points required for next Level: 41

    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Not sure how to read this data in




    Seems like there should be a simple solution here, but I'm struggling to find it.

    Trying to read in data from a .dat file. Here's an example of the first 2 entries:
    Code: 
    Generic College
    1234 Main St
    New York, NY                   12345
    718 555-1234
    One Star Liberal Arts
    Another Generic College
    567 Main St
    Boston, MA                23456
    617 555-5678
    Three Star Engineering
    Each entry has School Name on the first line, followed by street address then city, st & zip code followed by area code & phone # & then a generic rating scale (one-five star) & the focus of the school

    How I tried to read in the data:
    input name $ ;
    input address $ ;
    input city $ st $ zip $ ;
    input areacode $ phone $ ;
    input star $1-10 focus $ ;

    I'm using $ for all since I'm not actually manipulating the area or zip codes as numerical factors. I'm also using input in this fashion as I thought it would input in each line just as I wrote it and then I do do some kind of do loop to repeat throughout the rest of the data (a few thousand entries). However, it's not quite outputting it as planned. The name of the first college was skipped over & it's only reading info on each line up to the first space (ie - 1234 as the address instead of 1234 main st).


    I'm at a loss of how to read in the data when each entry is separated on multiple lines. Each address & name and city is differing in length, so it's not like I can just use "input name $1-34." I think if I can get over this small hurdle that I can use a do loop to read in successive entries. Every dataset I've used/seen with SAS has had info posted in a very vanilla fashion:
    name address city state zip phone stars focus
    Where all info for each entry is on the same line, making it easier to read in


    Any suggestions/advice for me to follow?

  2. #2
    Points: 2,895, Level: 32
    Level completed: 97%, Points required for next Level: 5

    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Not sure how to read this data in


    A good start is to use line pointers in the input statement (i.e., input #1 name $ 23. #2 address $ 12. etc). Where #1 refers to line one or the college name.

+ Reply to Thread

           




Similar Threads

  1. Read data from word file
    By jhavm in forum SAS
    Replies: 1
    Last Post: 05-07-2011, 12:23 PM
  2. read.table error
    By casact921 in forum R
    Replies: 4
    Last Post: 11-10-2010, 12:19 AM
  3. How to read ANOVA test
    By satimis in forum Statistics
    Replies: 0
    Last Post: 08-18-2010, 02:50 AM
  4. Replies: 2
    Last Post: 05-03-2010, 06:46 AM
  5. Please Read This Before Posting
    By quark in forum Psychology Statistics
    Replies: 0
    Last Post: 11-10-2005, 12:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts






Advertise on Talk Stats