Q) How many data types are there in SAS?
SAS has only two types of variables: character and
numeric.
- numerical values—are stored in 8 bytes (about
14 or 15 significant digits, depending on your operating system) if you
don’t specify otherwise.
With length statement we can assign 3-8 bytes to any numeric variable. - Each
character value is assigned a fixed storage length explicitly by program
statements or by various rules that SAS has about the length of character
values.
If no length is assigned to a char variable by any prog statements then the length of char variable is 8 bytes.
Q)If a variable contains only numbers, can it be character data type?
Also give example
Answer: Yes, it depends on how you use the variable
Example: ID, Zip are numeric digits and can be
character data type.
Q)If a variable contains letters or special characters, can it be
numeric data type?
No, it must be character data type.
Q)What are _numeric_ and _character_ and what do they do?
AWill either read or writes all numeric and character variables in
dataset.
Q)How are numeric and character missing values represented internally?
A) Character as Blank or “ and
Numeric as.
Q)How does SAS handle variable type conversion.
If you define a numeric variable and assign the
result of a character expression to it, SAS tries to convert the character
result of the expression to a numeric value and to execute the statement. If
the conversion is not possible, SAS prints a note to the log, assigns the
numeric variable a value of missing, and sets the automatic variable _ERROR_ to
1.
If you define a character variable and assign the result of a numeric
expression to it, SAS tries to convert the numeric result of the expression to
a character value using the BESTw. format,
where w is the width of the character variable and has a maximum value of 32.
SAS then tries to execute the statement. If the character variable you use is
not long enough to contain a character representation of the number, SAS prints
a note to the log and assigns the character variable asterisks. If the value is
too small, SAS provides no error message and assigns the character variable the
character zero (0).
Q)Give an example where SAS fails to convert character value to numeric value
automatically?
A)Suppose value of a variable PayRate
begins with a dollar sign ($). When SAS tries to automatically convert the
values of PayRate to numeric values, the dollar sign
blocks the process. The values cannot be converted to numeric values.
Q)Data type conversion
1)
X=’50’
Y=5*X;
Then the value of Y will be 250 and a note will be written in SAS log that
‘Char values have been converted to numeric value…..’
2)
X=’$50’
Y=5*X;
Y will be assigned missing value.It will result in error while converting char values to numeric.
Joe xx
The following SAS program is submitted:
data test;
infile ‘namenum’;
input name $ number;
run;
Which one of the following is the value of the NUMBER variable?
A. xx
B. Joe
C. . (missing numeric value)
D. The value can not be determined as the program
fails to execute due to errors.
As length of name is not specified and there is no
assignment statement to specify the length of name. So its length is 8 bytes.
So name goes on to read its 8 bytes and number variable is missing numeric
value.
Q)How do i convert a numeric variable to a character
variable?
You must create a differently-named variable using the PUT function.
Q)How do i convert
a character variable to a numeric variable?
You must create a differently-named variable using the INPUT function.
Q)Briefly explain Input and Put
function?
Input function –
Character to numeric conversion- Input(source,informat)
put function – Numeric to
character conversion- put(source,format)
No comments:
Post a Comment