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!

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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