SAS interview questions for analysts and statistical programmers

SAS interview questions test whether you know how the DATA step actually runs, not just which procedure prints a table. Expect the program data vector, RETAIN and BY-group processing with FIRST. and LAST., MERGE versus PROC SQL joins, WHERE versus IF, missing values and dates, the main procedures, and the macro language. Clinical and statistical programming roles add validation, double programming and data standards, and every level likes a debugging question about a log full of notes.

By Published 7 min read

Who gets SAS questions and how

SAS is still common in banking risk teams, insurance, government statistics and, above all, pharmaceutical and clinical research. Analyst interviews stay with data manipulation, summaries and reporting. Statistical programmer and clinical SAS programmer interviews go further into validation, macros, output tables for study reports and data standards. Many panels hand you a short program or a log and ask what it does or why it gives the wrong count, so practice reading code as well as writing it. Some teams also ask how you would do the same work in SQL or Python, since many shops run both.

DATA step fundamentals

First-round questions
QuestionWhat it testsWhat a strong answer shows
What is the program data vector (PDV)?Core modelThe memory area where the DATA step builds one row at a time. Variables read from input are loaded into it, new variables are computed there, and at the end of each iteration the row is written out.
What happens in the compile phase versus the execution phase?How SAS runsCompile checks syntax, builds the PDV and the descriptor of the output data set. Execution loops once per input observation, running the statements in order and writing output at the end.
What are _N_ and _ERROR_?Automatic variables_N_ counts iterations of the DATA step, _ERROR_ is set to 1 when a data error happens. Neither is written to the output data set.
Why does a new variable reset to missing each iteration?PDV behaviorVariables created by assignment are set to missing at the start of each iteration. Values read with SET or MERGE, and retained variables, are not.
What does RETAIN do, and how is the sum statement different?Carrying valuesRETAIN keeps a variable's value across iterations and can set a start value. The sum statement (total + amount) retains automatically, starts at zero and ignores missing values.
How are missing values stored and compared?Missing dataNumeric missing is a period, character missing is a blank. Numeric missing sorts and compares lower than any number, so a test like amount < 100 is true for missing values.
How long is a character variable?LengthsIts length is fixed when the compiler first sees it, from a LENGTH statement or the first value or input. Later longer values are truncated silently, a common bug.
Informat versus format?Reading and writingAn informat tells SAS how to read raw text into a value; a format controls how a stored value is displayed. Neither changes the stored value itself.
How does SAS store dates?DatesAs the number of days since 1 January 1960, so earlier dates are negative. Datetimes are seconds since midnight of that day. Formats such as DATE9. make them readable.
KEEP and DROP as statements or data set options?Variable controlStatements apply to the output data sets of the step. Data set options on an input data set limit what is read, which is faster with wide tables.
First-round questions. Scroll sideways on a small screen.
from datetime import date, timedelta

ORIGIN = date(1960, 1, 1)          # SAS day 0

def to_sas(d):   return (d - ORIGIN).days
def from_sas(n): return ORIGIN + timedelta(days=n)

print(to_sas(date(2024, 1, 1)))    # 23376
print(to_sas(date(1959, 12, 31)))  # -1, dates before 1960 are negative
print(from_sas(0))                 # 1960-01-01
Checking the date origin outside SAS (run with Python 3): 1 January 2024 is day 23376, 31 December 1959 is day -1.

Combining data and BY-group processing

proc sort data=visits out=visits_sorted;
  by patient_id visit_date;
run;

data patient_summary;
  set visits_sorted;
  by patient_id;
  retain n_visits;
  if first.patient_id then n_visits = 0;
  n_visits + 1;
  if last.patient_id then do;
    last_visit = visit_date;
    output;
  end;
  format last_visit date9.;
  keep patient_id n_visits last_visit;
run;
Not executed. One row per patient with the visit count and the last visit date, using FIRST. and LAST. on sorted data.
  • How do FIRST. and LAST. work? With a BY statement, SAS creates temporary flags that are 1 on the first and last row of each BY group. The data must be sorted or indexed by those variables, or the step stops with an error.
  • SET with two data sets versus MERGE? SET stacks them, one after the other. MERGE with BY joins them side by side on the key, like a join, and fills in matching rows.
  • What does the IN= option give you? A temporary flag for whether the current row came from that data set, so if a and b keeps matches, if a keeps everything from the first, if a and not b finds unmatched rows.
  • What goes wrong in a many-to-many MERGE? SAS pairs rows in order instead of producing every combination and writes a note about repeated BY values. Use PROC SQL when you really need a Cartesian match.
  • MERGE or PROC SQL join? MERGE needs sorted data and is efficient for one-to-one and one-to-many joins on the same key. PROC SQL needs no sorting, handles different key names, many-to-many joins and inequality conditions, and lets you summarize in one step.
  • WHERE versus IF? WHERE filters rows before they enter the PDV, so it is faster and works in procedures too, but it cannot use variables created in the same step. A subsetting IF works on the PDV after computation.
  • How do you remove duplicates? PROC SORT with NODUPKEY removes rows with duplicate BY values; NODUPRECS removes only rows identical to the previous one, so the result depends on the sort order.
  • Why is LAG inside an IF dangerous? LAG returns the value from the last time the function was executed, not the previous row. Inside a condition it skips rows, so compute it on every row first.

Procedures and output

Intermediate questions
QuestionWhat it testsWhat a strong answer shows
PROC MEANS versus PROC SUMMARY?SummariesThey compute the same statistics. MEANS prints by default; SUMMARY needs PRINT and is used for output data sets. CLASS groups without sorting, BY requires sorted data.
What does NWAY do?Class combinationsKeeps only the combination of all CLASS variables in the output, instead of every subtotal level marked by _TYPE_.
What does PROC FREQ give you?Categorical dataOne-way and cross tables, percentages, missing value handling with the MISSING option, and tests such as chi-square.
When do you use PROC TRANSPOSE?ReshapingTurning rows into columns or back, such as one row per patient and visit into one row per patient with a column per visit. ID names the new columns, BY keeps groups.
How do you create a custom format?PROC FORMATA VALUE statement maps values or ranges to labels, used to group or display data without changing it, like grouping ages into bands.
What is ODS?Output Delivery SystemIt routes procedure output to destinations such as RTF, PDF, Excel or HTML, and ODS OUTPUT captures any table a procedure produces as a data set.
How do arrays work in the DATA step?Repetitive logicAn array is a temporary name for a group of variables, processed with a DO loop, for example replacing missing values in twenty lab columns at once.
Which character functions come up most?Text handlingSUBSTR, SCAN, STRIP, COMPRESS, UPCASE, INDEX and the CAT family, especially CATX for joining with a separator while trimming blanks.
How do INPUT and PUT convert types?Type conversionINPUT reads a character value with an informat into a number; PUT writes a value with a format into text. Relying on automatic conversion leaves notes in the log and is risky.
INTCK and INTNX?Date arithmeticINTCK counts interval boundaries between two dates; INTNX moves a date by intervals, such as the first day of the next month.
Intermediate questions. Scroll sideways on a small screen.

Macros and senior questions

  • What is the macro facility for? It generates SAS code before it runs. %LET creates macro variables, %MACRO and %MEND define macros with parameters, and %DO loops repeat code generation.
  • Why does a macro variable not resolve in single quotes? The macro processor resolves references inside double quotes only. Use double quotes when the value must appear in a title or a string.
  • How do you pass a value from data to a macro variable? CALL SYMPUTX in a DATA step or SELECT INTO in PROC SQL. The value is available only after that step finishes, which trips people who use it in the same step.
  • How do you debug macros? Options MPRINT to see generated code, MLOGIC to follow macro logic, and SYMBOLGEN to see how references resolved. %PUT writes values to the log.
  • What do %EVAL and %SYSEVALF do? %EVAL does integer arithmetic on macro values; %SYSEVALF handles decimals. Comparing values as text by accident is a common macro bug.
  • When would you use a hash object? For fast lookups of a smaller table inside a DATA step without sorting either table, such as adding a description to millions of rows.
  • How do you validate output in a clinical team? Independent double programming, comparing data sets with PROC COMPARE, checking the log for warnings and notes, and reviewing against the specification. Teams often work with the CDISC data standards (SDTM and ADaM) in general terms.
  • How do you speed up a slow program? Read only the columns and rows you need with data set options and WHERE, avoid repeated sorts, use indexes or hash lookups, and summarize in the database when data sits there.
  • What notes in the log should worry you? Uninitialized variables, numeric-to-character conversion, missing values generated by operations, repeated BY values in a merge, and invalid data. Many teams treat them as failures.

Fictional example

Answering "Your merged data set has more rows than expected. Why?"
Interviewer
You merge a demographics data set with a lab results data set by subject ID and get more rows than there are lab results. What is going on?
Candidate
I would start with the log. If there is a note about repeated BY values, both data sets have duplicates on subject ID, so the merge is many-to-many and pairs rows in an order I did not intend. Demographics should have one row per subject, so I would check that with PROC SORT NODUPKEY into a separate data set and compare counts. If demographics is clean, the extra rows come from subjects that exist only in demographics, which a merge keeps unless I use IN= flags. I would add in=a and in=b, keep if b if I want one row per lab result, and write the unmatched subjects to a separate data set for review. Then I would confirm the final count with PROC FREQ or a simple count against the lab data.

How to prepare for SAS interview questions

  1. Explain the PDV out loudWalk through one DATA step iteration with a SET, an assignment and a RETAIN, saying what each variable holds.
  2. Write three group programsCounts per group with FIRST. and LAST., a running total, and the last record per key. Then redo one in PROC SQL.
  3. Practice merges and their trapsUnsorted data, unmatched keys, duplicate keys and different variable lengths on the key.
  4. Build one small macroA parameterized summary that loops over variables, debugged with MPRINT and SYMBOLGEN.
  5. Read logs on purposeBreak programs and learn what each note means, because log questions are common at every level.

SAS rounds often sit next to statistics and analysis questions: statistics interview questions covers the tests behind the procedures, and the data analyst guide covers the reporting and stakeholder side of the job.

Debugging answers sound better when you have rehearsed the order of your checks. Natively, an AI interview assistant for Mac and Windows, transcribes a mock SAS round on your computer so you can review whether you went to the log first. While you practice it can read a screenshot of a program or a log and suggest what to look at, and with Pro or the free trial it can use the résumé and job description you add. Every session leaves notes and a transcript behind.

Questions people ask

What are common SAS interview questions?

The program data vector, compile versus execution phase, RETAIN and the sum statement, FIRST. and LAST. processing, MERGE versus PROC SQL, WHERE versus IF, missing values, dates, PROC MEANS, FREQ and TRANSPOSE, and macro variables.

What is the difference between WHERE and IF in SAS?

WHERE filters rows before they enter the program data vector and works in procedures, but cannot use variables created in the same step. A subsetting IF filters after the row is in the PDV, so it can use computed values.

How does SAS store dates?

As the number of days since 1 January 1960, so earlier dates are negative numbers. Formats such as DATE9. display them as readable dates without changing the stored value.

What do clinical SAS programmer interviews add?

Validation through double programming and PROC COMPARE, macros for repeated tables, log review standards, and working with clinical data standards such as SDTM and ADaM in general terms.

Where to go next

Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.

Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP