BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
margi123
Fluorite | Level 6
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)
 
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

3 REPLIES 3
ballardw
Super User

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.

 

margi123
Fluorite | Level 6
In this question the answer is comes 22 but i do know how its come.

I think that the answer should come 11
Ksharp
Super User
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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 3 replies
  • 1100 views
  • 2 likes
  • 3 in conversation