These SAS interview questions and answers cover Base SAS concepts commonly discussed in interviews for freshers and experienced programmers. Topics include DATA and PROC steps, SAS libraries, input processing, formats and informats, the Program Data Vector (PDV), duplicate handling, automatic variables, joins, macros, and SAS log troubleshooting.

For experienced roles, interviewers may also ask you to explain how you validated a data transformation, investigated an unexpected row count, improved a slow program, or made reusable code safer. Prepare concise examples from projects you have worked on instead of memorising definitions alone.

Basic SAS interview questions and answers

Q1. What is the full form of SAS?

SAS stands for Statistical Analysis System. The name is also used for the software platform and its programming language.

Q2. What is the SAS System?

The SAS System is an integrated software environment for accessing, managing, analysing, and presenting data. Depending on the licensed products and deployment, it can be used for data preparation, statistical analysis, reporting, forecasting, visualisation, and application development.

Q3. What is a SAS program?

A SAS program is a sequence of SAS statements, normally organised into DATA steps, PROC steps, and global statements. Most SAS statements end with a semicolon. SAS keywords are generally not case-sensitive, although character data values can be case-sensitive.

Q4. How do you check whether the SASUSER library is read-only?

The RSASUSER system option indicates whether the SASUSER library is opened for read-only access. The following existing example displays the current option setting in the SAS log:

proc options option=rsasuser;
run;

If SASUSER is read-only, changing the option may require a new SAS session or an administrator-controlled configuration change. In managed SAS Studio environments, users should not assume that they can change server-level options themselves.

Q5. How do you assign a folder to a SAS library?

Use a LIBNAME statement to associate a libref with a physical folder or another supported data source. Redirecting the built-in SASUSER library is environment-dependent, so creating a separate user-defined library is usually clearer.

</>
Copy
libname mydata '/folders/myfolders/data';

Q6. What is a SAS library?

A SAS library is a collection of SAS files that SAS accesses through a short name called a libref. A library can contain data sets, views, catalogs, and other member types supported by the environment.

Q7. Which SAS libraries are commonly available by default?

  • WORK: A temporary library whose contents are normally removed when the SAS session ends.
  • SASHELP: A read-only library containing metadata views, sample data sets, and other supplied resources.
  • SASUSER: A user-specific permanent library when it is configured and writable.

Additional librefs, such as WEBWORK, may appear in particular products or server configurations and should not be treated as universal defaults.

Q8. What is the difference between temporary and permanent SAS libraries?

Data sets created with a one-level name are stored in WORK and are temporary. A permanent data set uses a two-level name consisting of a libref and member name, such as sales.orders. Its files remain after the session ends, subject to the storage system and retention policy.

Q9. What is a user-defined SAS library?

A user-defined library is one assigned explicitly with a LIBNAME statement or through the SAS interface. It can reference a local folder, a server location, or a database through an appropriate SAS/ACCESS engine.

Q10. What is a SAS statement?

A SAS statement is an instruction made from SAS keywords, names, literals, operators, and other language elements. Examples include DATA, SET, INPUT, IF, FORMAT, RUN, and TITLE. The statements that are valid depend on whether the program is in a DATA step, a PROC step, or open code.

SAS DATA step, PROC step, and input-processing questions

Q11. What is a DATA step in SAS?

A DATA step reads, creates, or modifies data one observation at a time. It can read raw files or existing SAS data sets, calculate variables, filter observations, combine data, and write one or more output data sets.

Q12. What is a PROC step in SAS?

A PROC step invokes a SAS procedure. Procedures perform defined tasks such as sorting, summarising, modelling, reporting, or managing data. For example, PROC SORT orders observations, while PROC MEANS calculates descriptive statistics.

Q13. What are global statements in SAS?

Global statements can generally appear outside DATA and PROC step boundaries and can affect later output or processing. Examples include TITLE, FOOTNOTE, OPTIONS, FILENAME, and LIBNAME. Their effects continue until changed, cancelled, or ended by the SAS session, depending on the statement.

Q14. Which SAS statement reads an external raw data file in a DATA step?

The INFILE statement identifies the external file and controls how records are read. An INPUT statement then describes the variables or input positions used to read each record.

Q15. What do the DLM and DSD options do in an INFILE statement?

  • DLM= specifies the delimiter used between values.
  • DSD treats consecutive delimiters as indicating a missing value, removes quotation marks surrounding character values, and allows delimiters inside quoted values to be treated as data.
</>
Copy
data work.customers;
    infile 'customers.csv' dsd dlm=',' firstobs=2;
    input customer_id name :$40. balance :comma12.2;
run;

Q16. What is the difference between a SAS informat and a format?

  • A SAS Informat tells SAS how to read a source value and convert it to an internal SAS value. Examples include MMDDYY10., DATE9., and COMMA12.2.
  • A SAS format tells SAS how to display or write a stored value without normally changing that stored value. Examples include DATE9., WEEKDATE., and DOLLAR12.2.

Q17. Which SAS functions are frequently discussed in interviews?

  • LENGTH: Returns the length of a character value, excluding trailing blanks under its standard character-function behaviour.
  • SUBSTR: Extracts characters from, or in assignment form modifies part of, a character value.
  • STRIP: Removes leading and trailing blanks.
  • SUM: Returns the sum of its nonmissing arguments; it differs from using the addition operator when an argument is missing.
  • INT: Returns the integer portion of a numeric value by truncating toward zero.
  • COALESCE: Returns the first nonmissing numeric argument. COALESCEC provides corresponding character behaviour.

Q18. What is the difference between a trailing @ and a double trailing @@?

  • Trailing @: Holds the current input record for another INPUT statement during the same DATA step iteration. The hold is released when SAS returns to the top of the DATA step or executes an INPUT statement without a trailing hold specifier.
  • Double trailing @@: Holds the input record across DATA step iterations. It is commonly used when one raw-data line contains multiple observations.

Q19. When should you use SELECT-WHEN instead of IF-THEN/ELSE?

SELECT-WHEN is useful when several mutually exclusive branches examine one expression or represent a clear set of alternatives. It can make such logic easier to read and maintain. IF-THEN/ELSE is often more suitable for unrelated conditions, ranges, or complex Boolean expressions. Performance should be measured rather than assumed from the choice of construct alone.

Q20. How can a DATA step run without creating an output data set?

Use the special data set name _NULL_. A DATA _NULL_; step executes DATA step logic but does not create a SAS data set. It is useful for writing files, creating macro variables, or producing customised output.

</>
Copy
data _null_;
    set work.orders end=last;
    total + amount;
    if last then put 'Total amount=' total comma12.2;
run;

SAS macros, duplicate records, and PDV interview questions

Q21. How do SAS macros support code reuse?

The SAS macro facility generates SAS text before the generated code is compiled and executed. Macro variables substitute values, while macros can generate repeated or conditional program sections. They are useful for parameterising programs, but generated code should still be inspected and tested.

Q22. How do you remove duplicate observations with PROC SORT?

Use NODUPKEY to keep one observation for each BY-group key after sorting. Use NODUPRECS to remove adjacent observations that are identical across all variables compared by PROC SORT. These options solve different problems, so the key defining a duplicate must be stated explicitly.

</>
Copy
proc sort data=work.customers
          out=work.unique_customers
          nodupkey;
    by customer_id;
run;

When it matters which duplicate is retained, sort by both the business key and a priority variable first. For example, sorting by customer ID and descending update timestamp can retain the latest row when followed by appropriate DATA step logic.

Q23. What is the Program Data Vector in SAS?

The Program Data Vector (PDV) is the logical area of memory in which a DATA step builds one observation at a time. During compilation, SAS determines variable attributes and constructs the PDV. During execution, values are read or calculated in the PDV and then written to an output data set when applicable.

Q24. What are the automatic variables _N_ and _ERROR_?

  • _N_: Counts DATA step iterations. It starts at 1 and is incremented before each iteration.
  • _ERROR_: Is normally 0. SAS sets it to 1 for the current iteration when it detects certain data or execution errors, such as invalid input.

Both variables are available during DATA step processing but are not written automatically to the output data set.

Q25. What does the SAS log note about numeric-to-character conversion mean?

It means SAS performed an implicit type conversion because an expression or function expected character data but received a numeric value. The reverse note appears when character data is converted to numeric. Implicit conversion can hide data-quality problems, so production code should normally use explicit functions such as PUT for numeric-to-character conversion and INPUT for character-to-numeric conversion.

Advanced SAS programmer interview questions

Q26. What is the difference between WHERE and IF in SAS?

A WHERE statement selects observations before they enter the PDV and can often use an index when reading a SAS data set. A subsetting IF statement evaluates after the observation has entered the PDV. WHERE cannot normally refer to a variable newly created in the same DATA step, whereas IF can evaluate calculated variables after they have been assigned.

Q27. What is the difference between SET and MERGE?

SET reads observations from one or more data sets. With multiple inputs, it commonly stacks data sets vertically. MERGE combines observations horizontally, usually by one or more BY variables. Inputs used in a BY-group match-merge generally need to be sorted by the BY variables or have suitable indexes.

Q28. How do IN= data set options help validate a SAS merge?

The IN= option creates a temporary Boolean indicator showing whether the current observation includes data from a specified input data set. These indicators can be used to create matched and unmatched outputs and to check merge coverage.

</>
Copy
data work.matched work.only_customers work.only_orders;
    merge work.customers(in=in_customers)
          work.orders(in=in_orders);
    by customer_id;

    if in_customers and in_orders then output work.matched;
    else if in_customers then output work.only_customers;
    else output work.only_orders;
run;

Q29. What is the difference between FIRST.variable and LAST.variable?

When a BY statement is used, SAS creates temporary FIRST.variable and LAST.variable indicators for each BY variable. FIRST.variable is 1 for the first observation in a BY group, and LAST.variable is 1 for the last. They are commonly used for group totals, sequence numbers, and selecting one row per group.

Q30. How do you investigate unexpected results in a SAS program?

  • Read the SAS log for ERROR, WARNING, and relevant NOTE messages.
  • Check input and output observation counts at each important step.
  • Verify variable types, lengths, formats, missing values, and key uniqueness.
  • Use PROC CONTENTS, PROC FREQ, PROC MEANS, or small PROC PRINT samples to inspect the data.
  • Test joins and merges for unmatched keys and many-to-many relationships.
  • Run a reduced reproducible example before changing the full program.

Q31. What is the difference between a SAS DATA step merge and a PROC SQL join?

A DATA step match-merge processes BY groups and is closely tied to SAS DATA step behaviour. PROC SQL joins use SQL join conditions and can express inner, left, right, full, and non-equijoins directly. The two methods can produce different row counts when keys are duplicated, especially in many-to-many cases. An interview answer should explain the expected key cardinality and how the result was validated.

Q32. What is the difference between a macro variable and a DATA step variable?

A macro variable stores text used by the macro processor to generate SAS code. A DATA step variable is part of DATA step processing and normally has a defined type, length, and value for each observation. Macro resolution occurs before the resulting SAS statements are compiled, so macro variables should not be described as ordinary columns in a data set.

Clinical SAS interview topics to prepare

Clinical SAS interviews can extend beyond Base SAS programming. The exact questions depend on the role, organisation, study phase, and standards used. A candidate may be asked about:

  • Reading source data and preserving traceability through derived data sets.
  • Validation approaches, independent programming, and comparison of outputs.
  • Handling dates, partial dates, missing values, controlled terminology, and treatment groups.
  • Producing and checking tables, listings, and figures.
  • Documenting assumptions, reviewing logs, and resolving data discrepancies.
  • Relevant CDISC concepts, such as SDTM and ADaM, when they are required by the position.

Do not claim experience with a clinical standard or regulatory workflow unless you can explain how you used it, what you validated, and which documentation governed the work.

SAS interview preparation checklist

  • Explain DATA step compilation and execution in your own words.
  • Practise reading the SAS log and identifying implicit conversions, uninitialised variables, and invalid data.
  • Prepare examples using SET, MERGE, BY-group processing, PROC SORT, PROC SQL, formats, informats, and functions.
  • Know how duplicate keys affect NODUPKEY, DATA step merges, and SQL joins.
  • Be ready to discuss row-count checks, reconciliation, and validation rather than only code syntax.
  • For experienced roles, prepare one example of a defect you diagnosed and one program you made more reliable or maintainable.
  • Review the specific SAS products, industry standards, and responsibilities named in the job description.

Frequently asked questions about SAS interviews

Are these SAS interview questions suitable for freshers?

Yes. Freshers should focus first on libraries, DATA and PROC steps, the PDV, input processing, formats and informats, functions, sorting, and basic data combination. They should also be able to write and explain a short program without relying on memorised definitions.

What should an experienced SAS programmer prepare for an interview?

Experienced candidates should prepare project examples involving validation, performance investigation, reusable code, difficult joins or merges, production defects, and communication with data owners or reviewers. Answers should state the problem, the checks performed, the decision made, and the verified result.

How should I answer a SAS coding question during an interview?

Clarify the input structure, expected output, key uniqueness, missing-value rules, and required ordering before writing code. Then explain the chosen method, mention likely log or data checks, and identify edge cases such as duplicate keys or type mismatches.

Which SAS log messages should I know for an interview?

Be prepared to explain errors, warnings, invalid-data notes, uninitialised-variable notes, automatic character-to-numeric or numeric-to-character conversion, missing values generated by operations, and messages about repeated BY values or merge behaviour. The correct response is usually to diagnose the underlying data or code issue rather than suppress the message.