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
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:
FORMATTED input as corrected:
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.
cynthia
Go to column 45 and read the first ten characters, so the equivalent of reading from columns 45-54, inclusive.
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
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".
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.
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.
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
This is the slide where I found the exercise
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:
FORMATTED input as corrected:
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.
cynthia
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.