Very Basic
Very Basic
Q1.What SAS statement would you code to read in an external raw data file to a DATA step?
data set
infile <fileref>;
run;
incase of .xls
2.proc import
3.by using the proc import option in the sas wizard of file
menu option.
Ans. Use KEEP or DROP depending on the number of varibales you require.
Drop: It meaning less to use KEEP when you want to use 35-40 variables. Its better to drop the
remaining variables.
Q3.Are you familiar with special input delimiters? How are they used?
Ans. We can specify delimiter value in dlm option of infile stmt.If any values are missing in between
then dlm option does nt recognize the same so we need to use DSD option to read consecutive delimiter
as missing values.DSD set two more things
Ans. the MISSOVER keyword; it forces SAS to put either a blank or a period for the missing variable
before continuing to the next record.
Q5. What is the difference between an informat and a format? Name three informats or formats.
Ans. informat - the format used to read the variable from raw data.informat is the option which is
used to read the data from the extral file or data lines,cards, internal data.
or
format - the format used to print the values of the variable. format is the option which is used to
print the data in the particular way, if you declare the format option in the data set block it will
stored permanently, were as if you put the format in the procedure block, it will temporary for
the printing purpose.
Q6.Name and describe three SAS functions that you have used, if any?
Ans. 1)TRIM
2)SUBSTR
3)ABS
syntax=trim(argument)
syntax=substr(argument,position<,n>)
syntax=abs(argument)
Q7. How would you code the criteria to restrict the output to be produced?
Ans. We can use,
where clause
no print
ods,
Q8. What is the purpose of the trailing @? The @@? How would you use them?
Ans. Both are line-hold specifiers; the difference is how long they hold a line of data for input.
The trailing @ holds aline of data for subsequent INPUT statements, but releasesthat line of
data when SAS returns to the top of the DATA step to begin building the next observation.
The double trailing @ holds a line of data for subsequent INPUT statements even when SAS
starts building a new observation.
In both cases, the line of data is released if SAS reaches a subsequent INPUT statement that
does not contain a line-hold specifier.
Q9. Under what circumstances would you code a SELECT construct instead of IF statements?
Q10. What statement do you code to tell SAS that it is to write to an external file? What statement do
you code to write the record to the file?
Ans. DATA
_NULL_;
SET MYDATA;
FILE '<FILE-LOCATION>';
PUT var1 var2 var3 ... varn;
RUN;
Q11. If reading an external file to produce an external file, what is the shortcut to write that record
without coding every single variable on the record?
Q13. What is the one statement to set the criteria of data that can be coded in any step?
Ans. WHERE Statement can be used to set the Criteria of the DATA in Both Proc Step and DATA step.
Q14. Have you ever linked SAS code? If so, describe the link and any required statements used to either
process the code or the step itself?
Q15.How would you include common or reuse code to be processed along with your statements?
Q16. When looking for data contained in a character string of 150 bytes, which function is the best to
locate that data: scan, index, or indexc?
Ans. Scan
Q17. If you have a data set that contains 100 variables, but you need only five of those, what is the code
to force SAS to use only those variable?
Q18. Code a PROC SORT on a data set containing State, District and County as the primary variables,
along with several numeric variables.
Run;
Ans. Nodupkey
Q21. How would you code a merge that will keep only the observations that have matches from both
sets.
Q22. How would you code a merge that will write the matches of both to one data set, the non-matches
from the left-most data set to a second data set, and the non-matches of the right-most data set to a
third data set.