Help using Base SAS procedures

Reading from Raw Data Files

Reply
Occasional Contributor
Posts: 9

Reading from Raw Data Files

Given the raw data file EMPLOYEE:

----I----1 0---I----20---I----30

Ruth 39 11

Jose 32 22

Sue 30 33

John 40 44

The following SAS program is submitted:

data test;

infile `employee';

input employee_name $ 1-4;

if employee_name = `Ruth' then input idnum 10-11;

else input age 7-8;

run;

What value does the variable IDNUM contain when the name of the employee is "Ruth"?

A. 11

B. 22

C. 33

D. (missing numeric value)

Thanks for answering in advance,

Smiley Happy

SAS Super FREQ
Posts: 8,743

Re: Reading from Raw Data Files

Hi:

  There is a HUGE difference between showing the data in a "fixed pitch" font and showing the data in a proportional spaced font, especially when your INPUT statement uses column positions.

  Again, to find out the answer to this question, you would type the data into a file, save the file as EMPLOYEES on your hard drive. Then probably amend the INFILE statement to use a fully qualified path. So, for example, if you save EMPLOYEES into c:\temp, the only modification would be to alter the INFILE statement: INFILE 'C:\temp\employees';

  Instead of answering the question for you, I am curious what results you discovered when you ran the program.

cynthia

Occasional Contributor
Posts: 9

Re: Reading from Raw Data Files

I did run the program and it gave a data error. See log message below:

NOTE: Invalid data for idnum in line 3 1-2.

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9

3         Jose 32 22 10

employee_name=Ruth idnum=. age=. _ERROR_=1 _N_=1

NOTE: Invalid data for age in line 7 1-2.

7         John 40 44 10

employee_name=Sue idnum=. age=. _ERROR_=1 _N_=2

What is unconvincing is the IF-THEN logic being used, which obviously makes me question the authenticity of online sample papers available for Base SAS exam.

if employee_name = `Ruth' then input idnum 10-11;

else input age 7-8;


Thanks, anyways, Cynthia. Smiley Happy

                                    
                             
Occasional Contributor
Posts: 9

Re: Reading from Raw Data Files

Forgot to add that after running the program, the output window showed missing values for the variables IDNUM and AGE. NAMES did appear though.

Gavy

Occasional Contributor
Posts: 9

Re: Reading from Raw Data Files

Cynthia and everyone,

I am preparing for Base SAS certification exam and was looking for a few practice papers. Would you like to recommend any useful sites, links from where I could access sample questions either free of charge or maybe paid(but not too expensive!)? Smiley Happy

Much Appreciated!

Gavy

Regular Learner
Posts: 1

Re: Reading from Raw Data Files

hi cynthia,

please explain the how pointer is reading the data. i am unable to comprehend the outcome. please help.

Super User
Super User
Posts: 6,502

Re: Reading from Raw Data Files

Unless the actual question has an indication that the lines are shorter than 11 characters then you cannot tell if the right answer is D or None of the above.

If we replace the spaces with periods the actual input line for "Ruth" could be either of the lines below. In the first the value will be missing as it will try to read from the next line when it runs out of characters.  In the second example the value will be 1 since it reads '1 ' from columns 10 and 11.


----|----10---|----20---|----30

Ruth.39.11

Ruth.39.11....................

Ask a Question
Discussion stats
  • 6 replies
  • 817 views
  • 0 likes
  • 4 in conversation