BookmarkSubscribeRSS Feed
v_dangkh
Calcite | Level 5

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
 

 

4 REPLIES 4
ChrisHemedinger
Community Manager

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!

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
v_dangkh
Calcite | Level 5

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 😕

ChrisHemedinger
Community Manager

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.

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1168 views
  • 0 likes
  • 3 in conversation