Making a Report Flashcards

1
Q

Notation and facts about:

  1. Block comment (and 3 facts about them)
  2. Comment statement
A

Block comments: /* comment */

  • Can be any length and contain semicolons.
  • Cannot be nested.
  • Avoid placing in first or second columns because SAS might interpret them as signal to end job or session

Comment statement: * comment statement ;

  • They can begin in columns 1 and 2
  • Cannot contain internal semicolons
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

4 common syntax errors

A

invalid options, missing semicolons, unmatched quotation marks, and misspelled keywords

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Is a user-created library automatically available in a SAS session?

A

NO, must assign a libref to make it available.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

LIBNAME statement

A

LIBNAME libref ‘filepath’

filepath = physical location of the library

Note: does not need a run statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

rules for naming libref

A
  1. 1-8 characters long
  2. Must begin with letter or underscore
  3. Remaining characters can be letters, numbers, or underscores
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

T or F: Macro variables can be referenced in double or single quotation marks

A

False. Macro variables can only be referenced in double quotation marks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. How do you generate a report of a library’s contents?
  2. How do you suppress descriptors data of each individual file in the library?
A
  1. PROC CONTENTS DATA = libref._ALL_;

RUN;

  1. PROC CONTENTS DATA = libref._ALL_ nods;

RUN;

nods = no descriptors

(make sure to add space before nods)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you distinguish numerical and character variables on a table?

A

SAS automatically displays numerical variable right-aligned and character variables left-aligned

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to dissociate a library?

A

LIBNAME libref clear;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does SAS display missing values for character and numeric variables?

A

Character: blank

Numeric: . (period)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Change what SAS displays for missing numeric values

A

MISSING = ‘character’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Length for character and numeric values

A

Character: 1 - 32,767 bytes

Numeric: 8 bytes (16 or 17 significant digits)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Rules for naming variables

A
  1. Can be 1 -32 characters long
  2. Start with letter or underscore
  3. Can contain numbers, letters, or underscores
  4. Can be uppercase or lowercase
  5. After variable is created, can refer to it in any case in code without affecting way in which it’s stored
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to add totals of several variables within one SUM statement

A

Separate variable with blank:

SUM var1 var2;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which statement do you use to choose specific variable to display in a report?

A

VAR

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to subset observations in a report?

A

Within PROC PRINT, use WHERE statement

17
Q

Use where statement to select variables that equal to one in a list

A

WHERE variable in (‘condition1’, ‘condition2’)

or WHERE variable in (‘condition1’ condition2’)

18
Q

What happens when you use 2 consecutive WHERE statements?

proc print data=orion.sales;

where Country=’AU’;

where Salary<30000; run;

A

The second where statement replaces the first one! Intead use logical operators (AND, OR, NOT)

19
Q

Which operator do you use to include observations with a certain substring in a report? Which statement do you use it with? What is the symbol for it?

A

CONTAINS. WHERE. ?

WHERE variable CONTAINS ‘substring’;

or

WHERE variable ? ‘substring’;

Note: substring is case-sensitive

20
Q

Name 5 special operators that can only be used in a WHERE statement

A
  1. BETWEEN AND : WHERE Salary between 5000 and 10000
  2. WHERE SAME AND condition: add to a where expression.
  3. WHERE variable IS NULL: a missing value
  4. WHERE variable IS MISSING: a missing value
  5. WHERE variable LIKE: matches a pattern (use % for any number of characters or _ for one character)
21
Q

How do you replace the observation number column with another variable?

A

Use ID variable;

22
Q

How to sort observations?

A

Use PROC SORT before printing. Note that by default, SAS replaces the original data set unless you use to create a new dataset.

PROC SORT DATA = SASDataSet

[OUT = NewDataSet];

BY [descending] variable1 [decending] variable2 variable3;

RUN;

(Stuff inside [] is optional)

23
Q

How to generate reports by groups

A

Use BY variable; under PROC PRINT

Remember to sort by the variable first

24
Q

Where it is best to add a WHERE statement? PROC SORT or PROC PRINT

A

PROC SORT

25
Q

How to add titles and footnotes

A

Titlen ‘title’;

Footnoten ‘footnote’;

n = number 1-10. That’s the number of the title you add

Note that these are global statements. Will remain until you change, replace, or cancel them

26
Q

You have 3 titles. What happens if you add a new title1? What happens if instead you add a new title2?

A

All 3 previous titles get replaced by title1.

Title2 and title3 get replaced.

27
Q

How to cancel title/footnote?

A

Title;

footnote;

28
Q

How do you assign temporary labels to variables?

A

Under PROC PRINT, use LABEL statement

PROC PRINT data=data.set label;

LABEL variable1=‘label name’

  • Varible2=‘label name*’;
  • ˆ*RUN;

Note: remember to add the label option after PROC print.

29
Q

How to display a variable label in two lines

A

proc print data=data.set SPLIT=‘*’;

label variable=‘label*name’;

run;

* can be any symbol used to split the label

30
Q

In the following code, which where expression is evaluated first?

where age<=55 and (pulse>75 or area=’A’)

A

The expression in parenthesis

31
Q

How you do you create column subtotals for different levels of a variable in a PROC PRINT step?

A

Use SUM and BY statements;

e.g.

proc print data=my.data;

var variable1 variable2;

sum variable2;

by variable3;

run;

This will produce separate tables for each level of variable3 with the subtotal of variable2 for that level.

32
Q

What 4 things happen when an ID statement specifies the same variable as the BY statement in a PROC PRINT step?

A
  1. The Obs column is suppressed
  2. the ID/BY variable is printed in the left-most column
  3. Each ID/BY value is printed only at the start of each BY group and on the line that contains that group’s subtotal (If have sum statement)
  4. Shows all values in one table rather than separating in different tables according to BY groups.
33
Q

When using PROC PRINT, how do you display different BY groups on separate pages?

A

PAGEBY BY-variable;

e.g.

proc print data=dataset;

var variable1 variable2

sum variable2

by variable3

PAGEBY variable3;

run;

Note that the variable specified in PAGEBY must also be in the BY statement

34
Q
A