0% found this document useful (0 votes)
131 views5 pages

Very Basic

This document provides answers to various questions about basic SAS programming concepts. It discusses how to import raw data files, read in specific variables, handle special delimiters, prevent reading the next record if a variable is missing, describe the differences between informats and formats, explain some common SAS functions, restrict output, write to external files, include common code, and perform merges and sorts.

Uploaded by

Sweta Singh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views5 pages

Very Basic

This document provides answers to various questions about basic SAS programming concepts. It discusses how to import raw data files, read in specific variables, handle special delimiters, prevent reading the next record if a variable is missing, describe the differences between informats and formats, explain some common SAS functions, restrict output, write to external files, include common code, and perform merges and sorts.

Uploaded by

Sweta Singh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Very Basic

Q1.What SAS statement would you code to read in an external raw data file to a DATA step?

Ans. we can import the an external file in three ways to a sas

data set

1.libname libref<location of the sas data set library>;

filname fileref<path of the raw data file>;

data <data set name>;

infile <fileref>;

input <variable declarations>;

run;

incase of .xls

2.proc import

3.by using the proc import option in the sas wizard of file

menu option.

Q2.How do you read in the variables that you need?

Ans. Use KEEP or DROP depending on the number of varibales you require.

Keep: Out of 50 if you require to keep 20 variables it better to use keep.

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

1.comma as default delimiter

2.remove quotion from quted string


Q4. If reading a variable length file with fixed input, how would you prevent SAS from reading the next
record if the last variable didn’t have a value?

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.

syntax:-informat<variable name>>type of informat>

or

input<variable name><type of informat>

ex:-$w., $CHARw., commaw.d

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.

syntax:-format<variable name><type of format>.

ex:-date9., best., mmddyy10.

Q6.Name and describe three SAS functions that you have used, if any?

Ans. 1)TRIM

2)SUBSTR

3)ABS

TRIM:Removing the trailing blanks from character expressions.

syntax=trim(argument)

substr:extracts the substring from an argument

syntax=substr(argument,position<,n>)

abs:returns the absolute of the argument

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

obs= & firstobs=

ods,

to restrict the output to be produced.

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?

Ans. when you have a long series of mutually exclusive conditions.


select statement is reduced cpu time.and make the programme easier to read and debug

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?

Ans. data _null_;


infile 'path';
input;
file 'destination path';
put _infile_;
run;
Q12. If you’re not wanting any SAS output from a data step, how would you code the data statement to
prevent SAS from producing a set?

Ans. using _null_ in data statement


data _null_;
--
--
--
run;

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?

Ans. %include to link code.

Q15.How would you include common or reuse code to be processed along with your statements?

Ans. %inc statement to include piece of code

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?

Ans. KEEP statement.


keep var-1 var-2 var-3 var-4 var-5;

Q18. Code a PROC SORT on a data set containing State, District and County as the primary variables,
along with several numeric variables.

Ans. Proc sort data=one;

By state district country;

Run;

Q19. How would you delete duplicate observations?


Ans. Nodup

Q20. How would you delete observations with duplicate keys?

Ans. Nodupkey

Q21. How would you code a merge that will keep only the observations that have matches from both
sets.

Ans. Using "IN" variable option.


data three;
merge one(in=x) two(in=y);
by id;
if x=1 and y=1;
run;

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.

Ans. data new1 new2;


merge old1 (in=one) old2 (in=two);
if one and two then output new1;
else one and not two then output new2;
run;

You might also like