DATA Step, Macro, Functions and more

Base Certification

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Base Certification

Hi,

I found a question in the SAS base certification that I didn't undestand:

 

input @45 name $10;

Which input technique is used in the above statement?

a)column input

b)formatted input

c)list input

 

Why the correct answer is a?

What does it mean insert the column pointer control @45 and tell sas to read the tenth column?

 

Thanks,

Alessandro


Accepted Solutions
Solution
‎03-22-2016 03:27 PM
SAS Super FREQ
Posts: 8,743

Re: Base Certification

Hi:

  Ah, thanks for posting that image. I understand now.

 

  That slide is a quiz question from our class for Certification Prep Review: https://support.sas.com/edu/schedules.html?ctry=us&id=58 Did you take that class or did you get the book from someone else?

 

  When we teach that class, the instructor goes over the answers with the students. In the certification review class, we tell students that this is an example of how a missing period (.) can entirely change the meaning of this INPUT statement.
 
  IF the statement had been:
input @45 name $10.;
then the correct answer would have been B (FORMATTED input) and you would have been instructing SAS to start at position 45 and read 10 characters into the NAME variable.
 
  However, without the period after the $10, this is still a valid INPUT statement

input @45 name $10;

the @45 is merely a distractor because, even if you send the pointer to position 45, as soon as there is not an informat detected, then the remaining "name $10" turns into COLUMN input (Answer A) and you are instructing SAS to go to position 10 and ONLY read position 10 into the NAME variable. That is why when you try the code with test data, you will only see 1 character for NAME.

 

  So, for example, see the comparison of COLUMN input vs FORMATTED input in the SAS log and see what a difference NOT having a period makes between reading 1 position and reading 10 positions. I made a fake data file where every character was unique, so you could trace exactly what character was being read. Here is the data file quiz_cert.txt:

 

Quiz_Cert.txt:

ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz

 

COLUMN input as coded:

example_column_input.png

 

FORMATTED input as corrected:

example_formatted_input.png

 

 

Here is the full page from the class (quiz answers are at the back of the chapter. For this quiz, the correct answer is A; but with a single period added to the $10. then the correct answer would be B.

answer_forum_cert_question.png

 

cynthia

 

 

 

 

View solution in original post


All Replies
Super User
Posts: 17,828

Re: Base Certification

Go to column 45 and read the first ten characters, so the equivalent of reading from columns 45-54, inclusive.

 

 

Occasional Contributor
Posts: 9

Re: Base Certification

I use SAS Studio and if I run this example SAS reads only the tenth column so the value of the variable 'name' is 'n'

 

data ex.dat1;
input @45 name $10;
datalines;
departement
;
run;

 

It seems that SAS ignores the column pointer control @45

Super User
Posts: 10,500

Re: Base Certification

I suspect that you misstyped the actual input statement.

Double checkt to see if it was :

input @45 name $10.;  < note the . after 10

The $10. would say "read starting at column 45 using character format for 10 characters".

Occasional Contributor
Posts: 9

Re: Base Certification

By using $10. after the name of the variable everything work but in the exercise that I have found the input statement is written as I wrote in the first post. I don't know if it is an error or it has another meaning.

SAS Super FREQ
Posts: 8,743

Re: Base Certification

Hi:
Where did you find the exercise? Is it in one of the classes that we offer? Is it in a quiz in the Certification Prep Guide? Is it in the Practice Exam for one of the certifications? Without knowing WHERE the question came from, it is hard to answer your question about whether it has another meaning. Perhaps you were meant to correct the INPUT statement so it would work. You did not provide the FULL text of the question, only your code snippet. Usually, with our courses or the Prep Guide or the Practice exam, the code snippet is preceded by a full question. Without seeing the full text of the question that went with your code snippet, it is impossible to comment.

cynthia
Occasional Contributor
Posts: 9

Re: Base Certification

I have found the exercise in "SAS Certification Review: Base Programming for SAS9" at page 3-7.

The question that I have posted is exactly the same question question that I found in the book.

Occasional Contributor
Posts: 8

Re: Base Certification

Ciao Cynthia,

 

In this link http://support.sas.com/certify/creds/samples/ , there are a few examples, I hope that they will help you preparing your exam 

Occasional Contributor
Posts: 17

Re: Base Certification

I bought those questions, I dont think they are gonna be the solution to your search, you gonna need to read more about writing data sets from raw data, UCLA website, UC SanDiego and JMP have free and detailed information that might be more helpful than these questions,
Super User
Posts: 17,828

Re: Base Certification

Can you post an image please?
Occasional Contributor
Posts: 9

Re: Base Certification

This is the slide where I found the exercise

 

Solution
‎03-22-2016 03:27 PM
SAS Super FREQ
Posts: 8,743

Re: Base Certification

Hi:

  Ah, thanks for posting that image. I understand now.

 

  That slide is a quiz question from our class for Certification Prep Review: https://support.sas.com/edu/schedules.html?ctry=us&id=58 Did you take that class or did you get the book from someone else?

 

  When we teach that class, the instructor goes over the answers with the students. In the certification review class, we tell students that this is an example of how a missing period (.) can entirely change the meaning of this INPUT statement.
 
  IF the statement had been:
input @45 name $10.;
then the correct answer would have been B (FORMATTED input) and you would have been instructing SAS to start at position 45 and read 10 characters into the NAME variable.
 
  However, without the period after the $10, this is still a valid INPUT statement

input @45 name $10;

the @45 is merely a distractor because, even if you send the pointer to position 45, as soon as there is not an informat detected, then the remaining "name $10" turns into COLUMN input (Answer A) and you are instructing SAS to go to position 10 and ONLY read position 10 into the NAME variable. That is why when you try the code with test data, you will only see 1 character for NAME.

 

  So, for example, see the comparison of COLUMN input vs FORMATTED input in the SAS log and see what a difference NOT having a period makes between reading 1 position and reading 10 positions. I made a fake data file where every character was unique, so you could trace exactly what character was being read. Here is the data file quiz_cert.txt:

 

Quiz_Cert.txt:

ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz

 

COLUMN input as coded:

example_column_input.png

 

FORMATTED input as corrected:

example_formatted_input.png

 

 

Here is the full page from the class (quiz answers are at the back of the chapter. For this quiz, the correct answer is A; but with a single period added to the $10. then the correct answer would be B.

answer_forum_cert_question.png

 

cynthia

 

 

 

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 11 replies
  • 1106 views
  • 5 likes
  • 6 in conversation