BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Geo-
Quartz | Level 8

A raw data file is listed below.
1---+----10---+----20---+---
01/05/1989 Frank 11
12/25/1987 June 13
01/05/1991 Sally 9

 

The following SAS program is submitted using the raw data file as input:
data work.family;
infile 'file-specification';
input @1 date_of_birth mmddyy10.
@15 first_name $5.
@25age 3;
run;
proc print data=work.family noobs;
run;
Which one of the following is the result?
a. The program executes, but the age values are missing in the output.
b. The program executes, but the date values are missing in the output.
c. The program fails to execute because the age informat is coded incorrectly.
d. The program fails to execute because the date informat is coded incorrectly.
Correct answer: a
Values for the variable age are missing in the output because the informat for age is
coded incorrectly. Since
age is standard numeric input, it should use the w.d informat to
specify a field width of 3 in the INPUT statement.
You can learn about the
w.d informat in Reading Raw Data in Fixed Fields

 

 

I think maybe the answer and the explanation are not right?Since the point is at 24?and the age is integer,it is supposed to read one number for each?and no need to set its format into w.d

 

 

----------------------------------------------------------------------updade------------------------------------------------------------------------

1.JPG

this is the origin question on pdf file,mine paste seemd disorder the format.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

The response you received is correct, but the reason is totally wrong.  Consider what this means:

 

input age 3;

 

It means get the value of AGE from column 3.  That is a slash (part of the date), and thus an invalid numeric value.  Hence you get a missing value.

 

This INPUT statement has the same effect:

 

input @25 age 3;

 

It means "move to column 25, then take the value of AGE from column 3".  Given that you move to column 25, you need a dot to indicate that these are instructions.  This INPUT statement is different (and correct):

 

input @25 age 3.;

 

It means "move to column 25, then take the next 3 columns as the value of AGE".  The dot indicates that "3." represents instructions for reading AGE, not a location within the line of data.

View solution in original post

8 REPLIES 8
shahparth260
Quartz | Level 8
data work.family;
infile datalines;
input @1 date_of_birth mmddyy10. @11 first_name $5. @17 age 3./* w.d informat */;
datalines;
01/05/1989 Frank 11
12/25/1987 June  13
01/05/1991 Sally 9
;
run;

You are partially right. This explanation misleads you because of the following :

 

Originally

 

This program has two errors : 

 

1) Error due to pointer at 15 

2) Need to use w.d in format (Only this error is explained). 

 

I can say this explanation is not enough evidence for answer, however I can not consider it is wrong. 

It should include  error 1) and 2) for complete explanation. 

 

Note: when I used to solve my base sas questions I found many of that questions, so I need to run and check those program to verify that answer and explanation. I think you should try that.

 

I am sending you correct code as well. 

 

PS
Geo-
Quartz | Level 8

very thoughtful for your code.I have updated the question,and make it more clear,please confirm.thank you for your attention.

shahparth260
Quartz | Level 8

In this case, The explanation truly satisfied because you can execute code but gives you missing value as of you have not used w.d (3.0) which represent w= width and d =decimal. In our case,  wid=3 ( because age may be 100 which is hard to see ) and no decimal. 

 

I hope it makes clear now. Try with w.d format and with out you will surly see difference. 

PS
Astounding
PROC Star

The response you received is correct, but the reason is totally wrong.  Consider what this means:

 

input age 3;

 

It means get the value of AGE from column 3.  That is a slash (part of the date), and thus an invalid numeric value.  Hence you get a missing value.

 

This INPUT statement has the same effect:

 

input @25 age 3;

 

It means "move to column 25, then take the value of AGE from column 3".  Given that you move to column 25, you need a dot to indicate that these are instructions.  This INPUT statement is different (and correct):

 

input @25 age 3.;

 

It means "move to column 25, then take the next 3 columns as the value of AGE".  The dot indicates that "3." represents instructions for reading AGE, not a location within the line of data.

shahparth260
Quartz | Level 8

@Astounding: Thanks for correcting my comment for it and explained root of this.  I really appreciate it. @Geo- Please consider this explanation, Ignore mine. Not intended to mislead you. 🙂

 

 

PS
Kurt_Bremser
Super User

Use the {i} button for posting code, logs and other texts that needs fixed spacing and no changes (eg replacing smileys for colon-closing bracket).

 

nirupama1
Fluorite | Level 6

Hi All,

 

I am using below code -

 

data test;
infile cards truncover;
input name $ lname $ id $ 4.;
cards;
sita kumari 21 m
ram kumar 22 f
munn kumar 34 m
;
proc print;
run;

 

getting output as-

 Obs name lname id123

sitakumari21 m
ramkumar22 f
munnkumar34 m


While when I use (added colon) -

input name: $ lname: $ id: $ 4. ;

 

output-

Obs name lname id123

sitakumari21
ramkumar22
munnkumar34

 

Why such difference in id. output?

As far as I know both below codes mean the same

 

input name $ lname $ id $ 4.;

input name: $ lname: $ id: $ 4. ;

 

Then why such difference in output.Please help to understand.

Will be glad.

 

Thanks,

Niupama

PGStats
Opal | Level 21

$4. reads the next 4 characters (e.g. "21m") starting from the current pointer position. :$4. extracts the next field (stopping at the next field separator, e.g. "21") and then reads the string with the specified informat ($4.)

PG

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 8 replies
  • 2225 views
  • 2 likes
  • 6 in conversation