Data Manipulation 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 WHERE statement in the DATA step?

  • To create new columns in the output data set.
  • To rename the input data set.
  • To format existing columns in the output data set.
  • To filter rows based on a specified condition. (correct)

How do you create a new numeric column in a DATA step?

  • DATA output-table; SET input-table; col-name = expression; RUN;
  • DATA output-table; SET input-table; LENGTH new-column $ length; RUN;
  • DATA output-table; SET input-table; new-column = expression; RUN; (correct)
  • DATA output-table; SET input-table; FORMAT col-name format; RUN;

What function would you use to calculate the maximum of the provided values?

  • MEAN(arguments)
  • MAX(num1, num2...) (correct)
  • N(arguments)
  • SUM(arguments)

What does the DROP statement achieve in a DATA step?

<p>It excludes specified columns from the output data set. (B)</p> Signup and view all the answers

Which statement correctly formats a column in the DATA step?

<p>DATA output-table; SET input-table; FORMAT col-name format; RUN; (D)</p> Signup and view all the answers

How do you define the length of a character column in a DATA step?

<p>LENGTH char-column $ length; (C)</p> Signup and view all the answers

Which function is used to concatenate character strings while removing leading and trailing blanks?

<p>CATS(char1, char2,...) (A)</p> Signup and view all the answers

What is the result of using the SUM function with missing values in its arguments?

<p>It calculates the sum by ignoring all missing values. (D)</p> Signup and view all the answers

Signup and view all the answers

Flashcards

Creating a dataset copy

Creates a copy of an existing dataset, providing a new dataset without altering the original.

Filtering rows in a dataset

Filters rows in a dataset based on a specified condition.

Specifying columns in a dataset

Specifies which columns to include in a new dataset, excluding others.

Creating new columns

Calculates and creates new columns using expressions that operate on existing columns.

Signup and view all the flashcards

Summary statistics functions

Calculates summary statistics for numeric values in a dataset, ignoring missing values.

Signup and view all the flashcards

Character functions

Modifies the format of characters in a column, such as changing case or concatenating strings.

Signup and view all the flashcards

Date functions

Extracts date information from SAS date values, like retrieving the month or year.

Signup and view all the flashcards

Creating character columns

Creates a new character column with a specified length, allowing for data manipulation.

Signup and view all the flashcards

Study Notes

Reading and Filtering Data

  • Create a copy of data using DATA output-table; SET input-table; RUN;
  • Filter rows using WHERE expression in a DATA step. Example: DATA output-table; SET input-table; WHERE age > 25; RUN;
  • Specify columns in the output using DROP or KEEP. Example: DROP col1 col2; or KEEP col3 col4;

Formatting Columns

  • Format columns in a DATA step using FORMAT. Example: FORMAT col-name format;

Computing New Columns

  • Create new columns using expressions. Example new-column = expression;
  • SAS automatically assigns type and length to new columns. Character columns' length is based on the assigned string length.
  • Character strings must be quoted and are case-sensitive.

Using Functions

  • Calculate summary statistics using functions (e.g., SUM, MEAN, MIN, MAX, N). Exclude missing values by default.
  • Character functions like UPCASE, LOWCASE, PROPCASE are available.
  • Date functions extract parts of dates (e.g., MONTH, YEAR, DAY).
  • CATS concatenates strings.
  • SUBSTR extracts substrings.
  • MDY creates a date from month, day, year values.
  • TODAY returns the current date as a SAS date.
  • Use functions within expressions, like, new-column = function(arguments);

Conditional Processing

  • Use IF-THEN statements for simple conditions. Example: IF age > 65 THEN DO; statement; END;
  • Use IF-THEN-ELSE for more complex conditions. Example: IF age > 65 THEN DO; expensive; END; ELSE DO; cheap END;
  • Use IF-THEN-DO for multiple statements based on a condition. Example: IF score > 90 THEN DO; print 'Excellent'; grade = 'A'; END;

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 Program Rules and Results
17 questions
SAS Programming Quiz
48 questions

SAS Programming Quiz

MemorableChrysoprase4817 avatar
MemorableChrysoprase4817
SAS Program Structure Quiz
48 questions

SAS Program Structure Quiz

OrganizedEmpowerment1022 avatar
OrganizedEmpowerment1022
Use Quizgecko on...
Browser
Browser