Functions in SAS

The post is about Functions in SAS Software. Functions in SAS software are predefined routines that perform specific computations or transformations on data. They can be categorized into several types based on their functionality.

Introduction to Functions in SAS Software

SAS functions are predefined operations that perform specific computations on data, categorized by their purpose. Numeric functions handle mathematical calculations like rounding, summing, and logarithms. Character functions manipulate text data through substring extraction, case conversion, and concatenation. Date and time functions manage SAS date, time, and datetime values, enabling operations like extracting year/month/day or shifting dates by intervals.

In SAS, Statistical functions compute summary metrics such as mean, median, and standard deviation. Financial functions support business calculations like net present value and loan payments. Random number functions generate values from statistical distributions for simulations. Bitwise functions perform low-level binary operations. Array functions assist in managing array dimensions and bounds. Special functions include utilities for data type conversion and lagged value retrieval. Finally, file and I/O functions check file existence and manage input/output operations. Together, these functions streamline data processing, analysis, and reporting in SAS.

Here are the main types of functions in SAS Software:

Numeric Functions

Perform mathematical operations on numeric values. These functions are also called arithmetic functions.

FunctionShort Description
SUM()Sum of arguments
MEAN()Arithmetic mean
MIN() / MAX()Minimum/Maximum value
ROUND()Rounds a number
INT()Returns integer part of a number
ABS()Absolute value of the argument
SQRT()Square root
LOG() / LOG10()Returns the integer part of a number
Functions in SAS Software

Random Number Functions in SAS

These functions generate random numbers.

Random Number FunctionShort Description
RANUNI()Generates random numbers from Uniform distribution
RANNOR()Generates random numbers from a Normal distribution
RANBIN()Generates random numbers from a Binomial distribution

Financial Functions

The following are important and useful financial calculations.

Financial FunctionsShort Description
IRR()Internal rate of return
NPV()Returns Net Present Value
PMT()Loan payment calculation

Character Functions in SAS

Manipulate and analyze text (string) data. These functions can also be classified as character-handling functions.

Character FunctionsShort Description
SUBSTR()Extracts a substring from an argument
SCAN()Extracts a specified word from a string
TRIM() / STRIP()Removes trailing/leading blanks from character expression
UPCASE() / LOWCASE()Converts to uppercase/lowercase
CATX()Concatenates strings with a delimiter
INDEX()Finds the position of a
COMPRESS()Removes specific characters from a string

Statistical Functions

The following are some important functions for the computation of descriptive statistical measures.

Descriptive FunctionsShort Description
MEAN(), MEDIAN(), MODE()Returns measures of central tendencies, mean, median, and mode of the data
STD()Returns standard deviation
VAR()Returns the variance
N()Returns the count of non-missing values
NMISS()Returns the count of missing values

Date and Time Functions in SAS

These functions handle SAS date, time, and datetime values.

FunctionsShort Description
TODAY() / DATE()Returns the current date
MDY()Creates a date from month, day, year
YEAR() / MONTH() / DAY()Extracts year/month/day
INTCK()Computes intervals between dates
INTNX()Increments a date by intervals
DATEPART()Extracts the date from datetime
TIMEPART()Extracts time from datetime

Bitwise Functions

The following functions perform bit-level operations.

FunctionsShort Description
BAND()Bitwise AND
BOR()Bitwise OR
BNOT()Bitwise NOT

Array Functions

The following functions work with arrays.

FunctionsShort Description
DIM()Returns the size of an array
HBOUND() / LBOUND()Returns upper/ lower bounds of an array

Special Functions

Miscellaneous operations. These functions may be classified as conversion functions, too.

FunctionsShort Description
INPUT()Converts character to numeric/ date
PUT()Converts value to formatted text
LAG() / DIF()Access previous row values

File and I/O Functions

These functions handle file operations.

FunctionsShort Description
FILEEXIST()Checks if a file exists
FEXIST()Checks if a fileref exists

The SAS functions described above help us in data cleaning, transformation, and analysis in SAS programming/ Software.

First Year (Intermediate) Mathematics Quiz

MS Excel Visualization MCQs 13

Test your Excel skills with this 20-question MCQ quiz on advanced data visualization! The MS Excel Visualization MCQs quiz covers key chart types like bubble charts, scatter plots, waterfall charts, hierarchy charts, population pyramids, and gauge charts—essential for effective data storytelling. Perfect for analysts, students, and professionals looking to master Excel’s powerful visualization tools. Take the MS Excel Visualization MCQs quiz now and see how well you know Excel charts!

Online MS Excel Tables Query Quiz with Answers

1. When creating a Map chart, the countries (or states or regions) need to be in alphabetical order.

 
 

2. How can we adjust the vertical axis in the chart below to appear on the extreme left of the chart?

Population chart ms excel quiz

 
 
 
 

3. A waterfall chart is ideal for showing the cumulative impact of a series of positive and negative components.

 
 

4. If we re-created the chart below but did not include the main category (in the inner-most ring) and highlighted the main-sub-category as our first category instead, each country would be coloured differently.

MS Excel Visualization Quiz Q3

 
 

5. A bubble chart is like a scatter chart, with a third variable, and solves the problem of displaying three variables in a 2-dimensional chart.

 
 

6. To create a Population chart (population pyramid chart in demography) in Excel, we need to begin with a:

 
 
 
 

7. What is the likely cause of the equal-sized bubbles in this 2-D bubble chart?

bubble chart ms excel quiz 1

 
 
 

8. The key difference between the Change Colours and Themes functionalities in Excel is that Themes includes suggestions for fonts as well.

 
 

9. If we were to add a third set of data, which included the same three variables used to plot the graph below, where the bubble size is the company size, Excel will usually add the new data set in a new colour.

bubble chart ms excel quiz 2 size

 
 

10. Before creating a hierarchy chart, the data must be arranged correctly. The first column must contain the main category.

 
 

11. Consider the Gauge chart below. What would happen to this Combo chart if both chart elements were converted to a Doughnut?

Gauge Chart in MS Excel

 
 
 
 

12. In Excel, what is hierarchical data?

 
 
 

13. Before you create a hierarchy chart, you need to organise your data by size.

 
 

14. How can we add a picture that is incorporated in the chart, the way it has been below?

Chart with Picture MS Excel Quiz

 
 
 

15. What type of chart is the following?

Treemap chart in MS Excel Quiz 4

 
 
 
 

16. What is the most likely explanation for the Map chart appearing the way below?

Map Chart in MS excel Quiz

 
 
 

17. Outliers in scatter or bubble charts should always be removed, and no notes need to be made to supplement your chart.

 
 

18. If a waterfall chart is composed of data from different categories, the order of the categories will impact the shape of the waterfall in the chart.

 
 

19. What is the following chart type?

Funnel Chart MS Excel Quiz

 
 
 
 

20. Why are some parts of the world shaded in grey in the Map chart below?

map chart ms excel quiz

 
 
 

Online MS Excel Visualization MCQs with Answers

  • A bubble chart is like a scatter chart, with a third variable, and solves the problem of displaying three variables in a 2-dimensional chart.
  • What is the likely cause of the equal-sized bubbles in this 2-D bubble chart?
  • Outliers in scatter or bubble charts should always be removed, and no notes need to be made to supplement your chart.
  • If we were to add a third set of data, which included the same three variables used to plot the graph below, where the bubble size is the company size, Excel will usually add the new data set in a new colour.
  • In Excel, what is hierarchical data?
  • Before creating a hierarchy chart, the data must be arranged correctly. The first column must contain the main category.
  • Before you create a hierarchy chart, you need to organise your data by size.
  • If we re-created the chart below but did not include the main category (in the inner-most ring) and highlighted the main-sub-category as our first category instead, each country would be coloured differently.
  • What type of chart is the following?
  • The key difference between the Change Colours and Themes functionalities in Excel is that Themes includes suggestions for fonts as well.
  • A waterfall chart is ideal for showing the cumulative impact of a series of positive and negative components.
  • If a waterfall chart is composed of data from different categories, the order of the categories will impact the shape of the waterfall in the chart.
  • What is the following chart type?
  • How can we add a picture that is incorporated in the chart, the way it has been below?
  • When creating a Map chart, the countries (or states or regions) need to be in alphabetical order.
  • Why are some parts of the world shaded in grey in the Map chart below?
  • What is the most likely explanation for the Map chart appearing the way below?
  • To create a Population chart (population pyramid chart in demography) in Excel, we need to begin with a:
  • Consider the Gauge chart below. What would happen to this Combo chart if both chart elements were converted to a Doughnut?
  • How can we adjust the vertical axis in the chart below to appear on the extreme left of the chart?
MS Excel Visualization MCQs with Answers: Population chart ms excel quiz

Python Data Visualization Quiz

Essential SAS Interview Questions

This blog post covers essential SAS interview questions to help aspiring data analysts and SAS programmers prepare for technical interviews. It explains core concepts like the basic elements of a SAS program, creating permanent datasets, the role of the DATA step, and how SAS informats work. Each question is answered concisely with practical examples, making it a quick yet comprehensive guide for interview preparation related to SAS Programming.

Essential SAS Interview Questions

What are the Basic Elements needed to run a SAS Program?

To run a SAS program, the following basic elements are needed:

  • SAS Software – Install SAS (Base SAS, SAS Studio, or SAS University Edition).
  • SAS Program – A SAS Programming Script containing:
    • DATA Step – To create or modify datasets.
    • PROC Step – To analyze or process data (e.g., PROC PRINT, PROC MEANS).
  • Input Data – Can be internal (directly in the program) or external (CSV, Excel, etc.).
  • Output – Procedure Results (logs, reports, or new datasets).
  • SAS Environment – A workspace (SAS Display Manager, SAS Studio, or Enterprise Guide).

To run a SAS program, the following must be followed:

  • Every line/statement has a semicolon
  • Input statement
  • A data statement that defines the data set
  • A run statement
  • There must be a minimum of one space between each statement or word.

How do you create a Permanent SAD Data Set?

To create a permanent SAS dataset, one must:

  1. Assign a Library – Use the LIBNAME statement to link a folder where the dataset will be stored.
  2. Reference the Library – Prefix the dataset name with the library name.

Example of Creating a Permanent Dataset in SAS

LIBNAME mylib "C:\SAS\Data";  /* Define a library */  

DATA mylib.permanent_data; /* Creates a permanent dataset */
INPUT ID Name $ Age;
DATALINES;
1 imdad 45
2 Usman 30
3 Ali 24
;
RUN;

The following are key points to note

  • The dataset (permanent_data) is saved in the specified folder (C:\SAS\Data) even after the SAS session ends.
  • Without a LIBNAMESAS stores datasets temporarily in the WORK library (deleted after the session).

To access the data for later use:

LIBNAME mylib "C:\SAS\Data";  
PROC PRINT DATA=mylib.permanent_data;  
RUN;  

What is the data step known in SAS?

In SAS, the DATA step is a fundamental programming component used to:

  • Create or Modify Datasets – Read, transform, and manipulate data.
  • Process Raw Data – Import external files (CSV, Text, and Excel) or create data internally.
  • Perform Calculations & Conditional Logic – Using SAS functions, loops (DO-END), and IF-THEN-ELSE statements.
  • Clean & Prepare Data – Handle missing values, recode variables, merge datasets, etc.

Key Features of the DATA Step:

  • Begins with DATA the statement (names the dataset).
  • Use INPUT to define variables.
  • Can include SET, MERGE, UPDATE, or INFILE to work with existing data.
  • Ends with RUN; (or a subsequent PROC step).

Note that the Data Step is important because

  • The core of SAS data manipulation.
  • Used before most PROC (procedure) Steps for analysis/reporting.
  • Allows complex data transformations before analysis.

What is a SAS Data Set?

A SAS dataset is a structured data file used in SAS programming, organized in a table format with:

  • Rows (Observations) – Represent individual records (e.g., customers, transactions).
  • Columns (Variables) – Represent data attributes (e.g., ID, Name, Age).

The key Features of a SAS Data Set are:

  1. Stored in Libraries –
    • Temporary: WORK library (deleted after session).
    • Permanent: Saved in a user-defined library (e.g., LIBNAME mylib "C:\Data";).
  2. Two Parts:
    • Descriptor (metadata like variable names, types).
    • Data (actual values).
  3. File Extension: .sas7bdat for datasets, .sas7bcat for catalogs.

A SAS dataset is used for Data storage, manipulation, and analysis in SAS procedures (PROC steps).

What SAS informats are?

SAS informats are instructions used to read raw data (for example, from files or datalines) and convert it into a SAS-readable format. They define how SAS interprets input data (numbers, dates, text, etc.).

The key features of SAS informats are:

  • Used in INPUT statements (DATA step) or with INFILE/INFORMAT statements.
  • Syntax: INFORMAT variable_name <format>; or embedded in INPUT.
  • Common types:
    • Numeric: 8. (standard numeric), COMMA9. (with commas like 1,000).
    • Character: $10. (reads 10 characters).
    • Date/Time: DATE9. (e.g., 01JAN2023), MMDDYY10. (e.g., 01/01/2023).

The following is an example of SAS informats.

DATA example;  
INPUT @1 Name $10. @12 DOB MMDDYY10. @23 Salary COMMA9.;
DATALINES;
Imdad 01/01/1990 50,000
Usman 12/15/1985 75,000
;
RUN;
  • $10. reads 10-character text.
  • MMDDYY10. reads dates in MM/DD/YYYY format.
  • COMMA9. reads numbers with commas (e.g., 50,000).
Essential SAS Interview Questions

Describe Some Common SAS Informats.

The common SAS Informats are:

TypeExample InformatsUsage
Numeric8., COMMA9., PERCENT8.Reads standard, comma-separated, or percentage numbers
Character$10., $CHAR20.Reads fixed-length text
DateDATE9., MMDDYY10., YYMMDD10.Converts text to SAS dates
TimeTIME8., DATETIME20.Reads time/datetime values

Describe when to use SAS Informats.

The SAS informats should be used when:

  • Importing external files (CSV, text).
  • Reading non-standard data (e.g., dates in different formats).
  • Converting raw text into usable SAS variables.

Take a Test: GRE Sentence Completion

Statistics Help Statistics for Data Science & Analytics