08132014 12:54 PM
data temp;
length a 1 b 3 x;
infile 'file reference';
input a b x;
run;
What is the result?
A.The data set TEMP is created, but variable X is not created.
B. The data set TEMP is created and variable X has a length of 8.
C.The data set TEMP is not created because variable A has an valid length.
D. The data set TEMP is not created because variable A and B have invalid lengths.
The answer is C.
I couldn't understand the answer at all.
I also run the code, the result is that the data set TEMP is created with 0 observation, the length of variable a b x are 8 3 8.
SO the correct answer is B? Can anyone please kindly confirm the answer with me?
By the way, why the length of a cannot be set as 1? Thank you guys!
08132014 01:02 PM
length a 1 b 3 x;
The statement above creates three numeric variables, a, b and x. A cannot be 1 because the minimum length for a numeric variable is 3.
The statement below creates one character variable and two numeric variables. The default length of a numeric variable is 8.
length a $ 1 b 3 x; (equivalent to: length a $ 1 b 3 x 8
08132014 04:21 PM
Hi Jiwillis, how do you know it is "a" that should be the character variable? not "b" or "X"?
08132014 01:06 PM
Errors out for me.
data temp;
length a 1 b 3 x;
input a b x;
cards;
2 5 8
3 4 5
13 2 3
;
run;
LOG:
246 data temp;
247
248 length a 1 b 3 x;
 
352 22
1 1

352
ERROR 352185: The length of numeric variables is 38.
ERROR 22322: Expecting a numeric constant.
249
250 input a b x;
251 cards;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TEMP may be incomplete. When this step was stopped there were 0
observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
255 ;
256
257 run;
08132014 04:24 PM
Hi Reeza,
Even if I changed the length of variable a to 3, error still exists. By the way, if the data set is created with error, whether should we call the data set is created or not created? Thank you.
12 data temp;
13 length a 3 b 3 x;

22
1 1

352
ERROR 22322: Expecting a numeric constant.
ERROR 352185: The length of numeric variables is 38.
14 input a b x;
15 cards;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TEMP may be incomplete. When this step was stopped there were 0
observations and 3 variables.
WARNING: Data set WORK.TEMP was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
19 ;
20 run;
08132014 03:07 PM
Do you by chance have a typo for answer C and should read "A has an invalid length"?
08132014 03:11 PM
Sas is using floating point for numbers. Remember the slider.
By that avoid the misperception on counting the digits you see. They are meaningless for the numeric length. The minimum storage used in bytes is often 3 sometimes 2 never 1.
08132014 04:29 PM
Thanks Jaap!
08132014 04:32 PM
Thanks Jaap!
However, even if I changed the length of variable a to 3, error still exists. By the way, if the data set is created with error, whether should we call the data set is created or not created? Thanks again.
08142014 01:33 AM
Chouchou, The length statement is defining: variable(s) length variable(s) length etc. Those are always two words and the length can be numeric or string (indicated by$).
The errors are often displayed with a letter _ at the position the parser says it is wrong. With a monospace font (old hollerith cards) this will be aligned. In your post here it is a variable font. That _22 is at the position of the semicolon ;
It is telling then numeric constant after the x is missing.
08162014 11:30 AM
Hi Jaap,
Thank you for your quick reply. However I still don't understand why errors come out even if I changed the length of variable a to 3?
Can you please elaborate it for me, I would be greatly appreciate your help.
08162014 02:26 PM
chouchou ,
I copied your log but only changed the character type to "courier new"
see where the error occurs not at the variable a but after x
12 data temp;
13 length a 3 b 3 x;

22
1 1

352
ERROR 22322: Expecting a numeric constant.
ERROR 352185: The length of numeric variables is 38
This should give no errors. It is not useful caused by floating point properties.
data temp;
length a 3 b 3 x 5 ;
08132014 06:47 PM
Are you sure you copied the code from the question properly?
The addition of X to the LENGTH statement without a length following it is also an error and so none of answers is 100% correct.
But don't nitpick the answers.
C is still the best answer as it is the first error that will cause the data step to not run.
A can be eliminated because just the inclusion of X in the INPUT statement will cause it to be created.
D can be eliminated because there is nothing wrong with length specified for B.
The intent of the step was to read the raw data and make a dataset. The raw data will not be read. Also note that if a dataset named TEMP already existed then it will not be replaced because of the error. So B can be eliminated.