Data Preparation in SAS

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the purpose of the statement 'KEEP col-name;' in a DATA step?

  • To rename a column
  • To include specific columns in the output (correct)
  • To drop all columns except the specified one
  • To exclude specific columns from the output

What will the function SUM(num1, num2,...) do in a DATA step?

  • Calculate the median of the variables
  • Ignore missing values and calculate the sum (correct)
  • Count the number of nonmissing values
  • Calculate the maximum value among the variables

In the expression 'new-column = expression;' what must the expression yield for a newly declared column?

  • A value that matches the existing column type
  • Any valid type; SAS will auto-define attributes (correct)
  • A character string only
  • A numeric value only

What does the LENGTH statement do when creating a character column?

<p>Defines the storage length for a character variable (C)</p> Signup and view all the answers

What will the function LOWCASE(char1) do to a character string?

<p>Change all characters to lowercase (D)</p> Signup and view all the answers

Which DATA step statement is used to filter rows based on a condition?

<p>WHERE expression; (D)</p> Signup and view all the answers

What is the result of using the MAX(num1, num2,...) function?

<p>Returns the highest nonmissing value among the specified variables (D)</p> Signup and view all the answers

When creating a new numeric column, what default length does SAS assign to it?

<p>8 (B)</p> Signup and view all the answers

Signup and view all the answers

Flashcards

Creating a copy of data

Creates a copy of an existing table called input-table and names the new copy output-table.

Filtering rows in the DATA step

Filters rows in a table based on a condition specified in the WHERE clause.

Dropping columns in the DATA step

Specifies which columns to include in the output data set using DROP to remove columns.

Keeping columns in the DATA step

Specifies which columns to keep in the output data set using KEEP.

Signup and view all the flashcards

Computing new columns

Creates a new column or updates an existing one, defining its name, type, and length. The new column name appears on the left side of the equals sign, and the expression to calculate its value is on the right side.

Signup and view all the flashcards

Using functions in expressions

Uses functions in expressions to calculate new column values.

Signup and view all the flashcards

SUM function

The SUM function calculates the sum of numeric values, ignoring missing values.

Signup and view all the flashcards

CATS function

Concatenates multiple character strings into a single string.

Signup and view all the flashcards

Study Notes

Preparing Data in SAS

  • Reading and Filtering Data:

    • Create a copy of data using DATA output-table; RUN; SET input-table;
    • Filter rows using DATA output-table; RUN; SET input-table; WHERE expression;
    • Specify columns for the output dataset with DROP or KEEP in the DATA step.
  • Specifying Columns:

    • Include or exclude columns using DROP and KEEP statements.
    • Example: DROP col-name <col-name>; or KEEP col-name <col-name>;
  • Formatting Columns:

    • Format columns within the DATA step using FORMAT statement.
    • Example: FORMAT col-name format;
  • Computing New Columns:

    • Create new columns using expressions.
    • Example: new-column = expression; in the DATA step.
    • The column name to create or update is on the left. The expression for computation is on the right.
    • New numeric columns are 8 characters long.
    • Character columns automatically adjust length to the value assigned length. Character strings must be quoted and are case sensitive.
  • Example using functions: -Example : LENGTH char-column $ length; -Calculates summary stats (ignoring missing values): function(argument1, argument2, ...)

  • Functions:

    • Calculates common functions like sum, mean, median, range, min, max, count (non-missing and missing).
    • Character functions include changing case (upper/lower/proper) and concatenation.
    • Date functions extract values (month, year, day, weekday, quarter) or create SAS dates.

Conditional Processing

  • IF-THEN:

    • Execute a statement if a condition is met.
    • IF expression THEN statement;
  • IF-THEN-ELSE:

    • Execute one statement if a condition is true and another if it's false.
    • IF expression THEN statement; ELSE statement;
  • IF-THEN-DO:

    • Execute multiple statements if a condition is true.
    • IF expression THEN DO; <statements>; END;
  • Example of using IF-THEN-ELSE and IF-THEN-DO.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

SAS Programming Quiz
48 questions

SAS Programming Quiz

MemorableChrysoprase4817 avatar
MemorableChrysoprase4817
Data Manipulation in SAS
9 questions

Data Manipulation in SAS

NonViolentRutherfordium5305 avatar
NonViolentRutherfordium5305
Introduction to SAS Software
48 questions
Use Quizgecko on...
Browser
Browser