@JKim8069 wrote: Assuming the ID column in the employees table is numeric, which statement is true? 1 data convert; 2 set employees; 3 ID=put(ID, 5.); 4 run; 5 Answer: The step runs, but ID is not converted to a character column. My question: I can’t find any reason why ‘ID=put(ID, 5.)’ is wrong…. I appreciate your help.
‘ID=put(ID, 5.) isn't "wrong". This sort of quiz question to see if you understand the behavior in SAS that a variable doesn't change it's type.
One thing that is often revealing is to run code to TEST these types of questions. I know that during a scored quiz that may not be possible but if you do so you may see some revealing items. Running this to create a simple data set:
data employees;
input id ;
datalines;
12
1234
1234567
;
Then running your question code generates this Log.
231 data convert;
232 set employees;
233 ID=put(ID, 5.);
234 run;
NOTE: Character values have been converted to numeric
values at the places given by: (Line):(Column).
233:6
NOTE: There were 3 observations read from the data set WORK.EMPLOYEES.
NOTE: The data set WORK.CONVERT has 3 observations and 1 variables.
NOTE: At least one W.D format was too small for the number to be printed.
The decimal may be shifted by the "BEST" format.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
the (column) 6 means the position of the Put statement. So even though Put created a character value SAS shows the conversion message that it attempted to assign a character to numeric variable, which it basically doesn't, using internal automatic conversion routines.
I intentionally included a value of ID longer than would be used by a 5. format. See the Note about the W.D too small? That is because there were 7 digits for the last value and 5.0 (the w.d) can't display all of them.
If you look at the resulting data set Convert you will see that the last value of my example Employee set now has a value of 1230000.
That is because in the second part of the note the BEST. format was used instead of the 5 to do something with the value that wouldn't fit.
Two things to take away from this besides the fixed variable type:
1) READ THE LOG. Messages about conversions either way generally mean something may be going wrong with the values.
2) Make sure that you control any conversion. The are many places that SAS attempts to help when you may not realize that conversions may be needed. Generally things go okay but there are instances, such as this, where you may get quite different than expected results because of the use of the BEST format (and generally BEST12. by default).
... View more