BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alep92
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

11 REPLIES 11
Reeza
Super User

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

 

 

alep92
Fluorite | Level 6

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

ballardw
Super User

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".

alep92
Fluorite | Level 6

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.

Cynthia_sas
SAS Super FREQ
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
alep92
Fluorite | Level 6

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.

toconero
Fluorite | Level 6

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 

Muwanguzi
Obsidian | Level 7
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,
Reeza
Super User
Can you post an image please?
alep92
Fluorite | Level 6

This is the slide where I found the exercise

 

Cynthia_sas
SAS Super FREQ

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

 

 

 

 

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
  • 11 replies
  • 4452 views
  • 5 likes
  • 6 in conversation