DATA Step, Macro, Functions and more

value of variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

value of variable

Question 1) Can you please explain me with its answer? 
 
Given the raw data file EMPLOYEE:
----I----1 0---I----20---I----30
Ruth 39 11
Jose 32 22
Sue 30 33
24 SAS Institute A00-211 Exam
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)
 

Accepted Solutions
Solution
‎03-15-2017 08:09 PM
Super User
Posts: 10,500

Re: value of variable

[ Edited ]

Run the code.

Read the log.

 

IF the code you have pasted is what you actually run you should have errors like this:

162  infile `employee';.
            -        ---
            22       23
            200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string.

Note that the _ is under a character that looks like this: `

If you enter code into the editor and use the key to the right of the one with : you will get '   if you use the one in the upper left of the keyboard you get `  They are not the same character. SAS expects '  or " to surround character values.

the same thing happens with `Ruth'   you can see that the mark before the R is not the same as the one at the end.

 

Notice the code box with the log result. If I paste the same thing into the main body:

162 infile `employee';.

- ---

22 23

200

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string.

 

and we cannot see where the _ is indicating the error because the message board reformatted the text from the log.

 

There is another possible issue with the INFILE statement. If you use: Infile 'employee'; SAS will look for the file from the location that SAS is currently running which is very likely not to be where the file is located. You should specify a fully qualified path, which is operating system dependent, to the file. That different operating systems use different path structures is likely ignored for this test problem to make the question non-operating system dependent.

 

View solution in original post


All Replies
Solution
‎03-15-2017 08:09 PM
Super User
Posts: 10,500

Re: value of variable

[ Edited ]

Run the code.

Read the log.

 

IF the code you have pasted is what you actually run you should have errors like this:

162  infile `employee';.
            -        ---
            22       23
            200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string.

Note that the _ is under a character that looks like this: `

If you enter code into the editor and use the key to the right of the one with : you will get '   if you use the one in the upper left of the keyboard you get `  They are not the same character. SAS expects '  or " to surround character values.

the same thing happens with `Ruth'   you can see that the mark before the R is not the same as the one at the end.

 

Notice the code box with the log result. If I paste the same thing into the main body:

162 infile `employee';.

- ---

22 23

200

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string.

 

and we cannot see where the _ is indicating the error because the message board reformatted the text from the log.

 

There is another possible issue with the INFILE statement. If you use: Infile 'employee'; SAS will look for the file from the location that SAS is currently running which is very likely not to be where the file is located. You should specify a fully qualified path, which is operating system dependent, to the file. That different operating systems use different path structures is likely ignored for this test problem to make the question non-operating system dependent.

 

Occasional Contributor
Posts: 8

Re: value of variable

In this question the answer is comes 22 but i do know how its come.

I think that the answer should come 11
Super User
Posts: 9,676

Re: value of variable

input employee_name $ 1-4;

there is not @ at the end of it. So the point will go to the next line ,
therefore you will get 22.

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 177 views
  • 2 likes
  • 3 in conversation