DATA Step, Macro, Functions and more

Trouble Reading Raw Da'y'ta Files

Reply
Occasional Contributor
Posts: 6

Trouble Reading Raw Da'y'ta Files

Hello SAS Community,

 

I'm having trouble reading this data as

 

  1. Name has only single blanks between the first and last name.
  2. Phone contains only digits (and is still a character value).
  3. Data set Names_And_More contains a character an integer or a mixed number (such as 50 1/8).temporary SAS data set with a numeric variable number should be rounded to the nearest .001. Hint: Use the SCAN function with blanks and forward slashes (/) as delimiters.
  4. Using the Names_And_More data set, create a temporary SAS data set containing the phone number (Phone) and the 3-digit area code (AreaCode). Be sure the length of AreaCode is 3. You may need to list a few observations in Names_And_More to see how Phone is stored.

Listing of Data Set LEARN.NAMES_AND_MORE

Name Phone Height Mixed

 

DATA LEARN.NAMES_AND_MORE;
INFILE DATALINES;

DATALINES;
Roger Cody (908)782-1234 5ft. 10in. 50 1/8 Thomas Jefferson (315) 848-8484 6ft. 1in. 23 1/2 Marco Polo (800)123-4567 5Ft. 6in. 40 Brian Watson (518)355-1766 5ft. 10in 89 3/4 Michael DeMarco (445)232-2233 6ft. 76 1/3
;
RUN;

 

I would fully appreciate if someone can help me,

Thank you!

Spoiler
 

 

Community Manager
Posts: 2,955

Re: Trouble Reading Raw Da'y'ta Files

Hmm, looks like you are trying to Learn SAS By Example (with help from author Ron Cody).  Are you sure you want an answer from here? You won't learn very much that way!

Occasional Contributor
Posts: 6

Re: Trouble Reading Raw Da'y'ta Files

Posted in reply to ChrisHemedinger

Its for a school assignment, ive been trying so many methods but i cant get it to work.

Ive tried input @, #, column ranges, but the order is not correct :/

Community Manager
Posts: 2,955

Re: Trouble Reading Raw Da'y'ta Files

The following code will get your data input.  This INPUT statement tells SAS to read each field as a character string of the specified length (ex: 20 for Name).  The & tells SAS that the field might contain an embedded blank and not to stop reading just for that.

 

data names_and_more;
   input Name $ 20.
         Phone & $ 14.
         Height & $ 10.
         Mixed & $ 8.;
datalines;
Roger   Cody        (908)782-1234  5ft. 10in.  50 1/8
Thomas  Jefferson   (315) 848-8484  6ft. 1in.  23 1/2
Marco Polo          (800)123-4567  5Ft. 6in.  40
Brian Watson        (518)355-1766  5ft. 10in  89 3/4
Michael DeMarco     (445)232-2233  6ft.       76 1/3
;

I don't feel bad about giving this much to you, because this is supplied with the book materials as example code.  However, your task is to parse out the phone number and measurements into their component parts so that you can perform calculations, categorize by area code, etc.  I don't want to rob you of that learning opportunity, but I'll give you a hint about the fractions: it comes from our friends at sasCommunity.org.

Super User
Posts: 5,438

Re: Trouble Reading Raw Da'y'ta Files

Ask a Question
Discussion stats
  • 4 replies
  • 275 views
  • 0 likes
  • 3 in conversation