WEBVTT

1
00:00:00.000 --> 00:00:07.866 align:middle line:90%
You can use SAS programs to 
access, manage, analyze, and 

2
00:00:07.866 --> 00:00:11.199 align:middle line:90%
present your data. In this 
video, you learn to recognize 

3
00:00:11.200 --> 00:00:14.300 align:middle line:90%
the main components of SAS 
programs and write a basic SAS 

4
00:00:14.300 --> 00:00:19.100 align:middle line:90%
program. Let's begin by looking 
at an example. This program 

5
00:00:19.100 --> 00:00:22.466 align:middle line:90%
uses an existing SAS table to 
create a new table containing a 

6
00:00:22.466 --> 00:00:26.299 align:middle line:90%
subset of the original data. 
The second part of the program 

7
00:00:26.300 --> 00:00:30.000 align:middle line:90%
generates a list report of the 
new table. Let's see how this 

8
00:00:30.000 --> 00:00:34.766 align:middle line:90%
program works. The program 
contains two steps: a DATA step 

9
00:00:34.766 --> 00:00:39.032 align:middle line:90%
and a PROC step. These two 
types of steps, alone or 

10
00:00:39.033 --> 00:00:44.933 align:middle line:90%
combined, form most SAS 
programs. DATA steps typically 

11
00:00:44.933 --> 00:00:48.966 align:middle line:90%
create or modify SAS tables. 
You can use DATA steps to put 

12
00:00:48.966 --> 00:00:53.232 align:middle line:90%
your data in a SAS table, 
compute values, check for and 

13
00:00:53.233 --> 00:00:56.566 align:middle line:90%
correct errors in your data, 
and produce new tables by 

14
00:00:56.566 --> 00:01:00.432 align:middle line:90%
subsetting, supersetting, 
merging, and updating existing 

15
00:01:00.433 --> 00:01:05.833 align:middle line:90%
tables. PROC or procedure steps 
enable you to analyze or 

16
00:01:05.833 --> 00:01:09.833 align:middle line:90%
process the data in a table and 
present your data. You can use 

17
00:01:09.833 --> 00:01:13.799 align:middle line:90%
PROC steps to summarize, sort, 
and list data, produce 

18
00:01:13.800 --> 00:01:18.833 align:middle line:90%
descriptive statistics, and 
generate reports and graphs. 

19
00:01:18.833 --> 00:01:21.899 align:middle line:90%
You use a RUN statement to 
complete both DATA and PROC 

20
00:01:21.900 --> 00:01:27.000 align:middle line:90%
steps. The RUN statement tells 
SAS to execute the code. Now 

21
00:01:27.000 --> 00:01:30.700 align:middle line:90%
let's look at the individual 
statements in each step. Each 

22
00:01:30.700 --> 00:01:34.600 align:middle line:90%
step in a SAS program is made 
up of a sequence of statements. 

23
00:01:34.600 --> 00:01:37.900 align:middle line:90%
SAS statements usually begin 
with a SAS keyword and always 

24
00:01:37.900 --> 00:01:41.833 align:middle line:90%
end with a semicolon. The DATA 
step begins with a DATA 

25
00:01:41.833 --> 00:01:45.299 align:middle line:90%
statement, starting with the 
keyword DATA, followed by the 

26
00:01:45.300 --> 00:01:51.266 align:middle line:90%
name of the new table to be 
created, europeancars. Because 

27
00:01:51.266 --> 00:01:54.932 align:middle line:90%
this program is reading a SAS 
table, next you use the SET 

28
00:01:54.933 --> 00:02:01.199 align:middle line:90%
statement to specify the table 
sashelp.cars. Following the SET 

29
00:02:01.200 --> 00:02:04.133 align:middle line:90%
statement, the DATA step can 
contain additional programming 

30
00:02:04.133 --> 00:02:08.466 align:middle line:90%
statements. In this example, a 
WHERE statement specifies that 

31
00:02:08.466 --> 00:02:12.732 align:middle line:90%
the new table, europeancars, 
will include only those rows 

32
00:02:12.733 --> 00:02:16.766 align:middle line:90%
where the value of origin is 
Europe. The step ends with a 

33
00:02:16.766 --> 00:02:20.866 align:middle line:90%
RUN statement. Now let's look 
at the PROC step, in this case, 

34
00:02:20.866 --> 00:02:25.499 align:middle line:90%
a PRINT procedure. It begins 
with the keywords PROC PRINT, 

35
00:02:25.500 --> 00:02:28.900 align:middle line:90%
followed by the DATA= option 
and the name of the table used 

36
00:02:28.900 --> 00:02:33.833 align:middle line:90%
in the report, europeancars. By 
default, if no subsetting 

37
00:02:33.833 --> 00:02:37.399 align:middle line:90%
options are specified, the 
PRINT procedure lists all rows 

38
00:02:37.400 --> 00:02:42.800 align:middle line:90%
and columns. So let's submit 
the code and see what happens. 

39
00:02:42.800 --> 00:02:47.200 align:middle line:90%
I'll click Run. Notice that SAS 
displays program results 

40
00:02:47.200 --> 00:02:51.766 align:middle line:90%
immediately after the code has 
run. I'm going to check the log 

41
00:02:51.766 --> 00:02:54.732 align:middle line:90%
to make sure that the program 
ran without errors. There are 

42
00:02:54.733 --> 00:02:59.333 align:middle line:90%
no errors or warnings, so 
that's good. I see two sets of 

43
00:02:59.333 --> 00:03:03.099 align:middle line:90%
notes in the log, one for each 
step in the program. Let's look 

44
00:03:03.100 --> 00:03:07.400 align:middle line:90%
at each in turn. The first set 
of notes follows the code for 

45
00:03:07.400 --> 00:03:12.000 align:middle line:90%
the data step and indicates 
that SAS read 123 observations, 

46
00:03:12.000 --> 00:03:16.100 align:middle line:90%
or rows from the table 
sashelp.cars where origin 

47
00:03:16.100 --> 00:03:19.900 align:middle line:90%
equals Europe and created the 
table europeancars in a 

48
00:03:19.900 --> 00:03:25.066 align:middle line:90%
temporary library named work. 
The second set of notes follows 

49
00:03:25.066 --> 00:03:29.632 align:middle line:90%
the code for the PROC PRINT 
step. SAS read the 123 rows 

50
00:03:29.633 --> 00:03:34.533 align:middle line:90%
from work.europeancars and 
generated a list report. Now 

51
00:03:34.533 --> 00:03:37.233 align:middle line:90%
that I've confirmed that the 
code ran correctly, I'll look 

52
00:03:37.233 --> 00:03:41.199 align:middle line:90%
at the results. Here I see a 
report that lists all rows and 

53
00:03:41.200 --> 00:03:44.833 align:middle line:90%
columns for the europeancars 
table. The default results 

54
00:03:44.833 --> 00:03:48.699 align:middle line:90%
format is HTML, but I can use 
buttons on the toolbar to 

55
00:03:48.700 --> 00:03:54.366 align:middle line:90%
download the results in RTF or 
PDF format if needed. Now that 

56
00:03:54.366 --> 00:03:57.632 align:middle line:90%
you understand how SAS programs 
are structured, let's write one 

57
00:03:57.633 --> 00:04:02.766 align:middle line:90%
from scratch. Suppose I want to 
create a new table that is a 

58
00:04:02.766 --> 00:04:09.932 align:middle line:90%
subset of sashelp.heart. The 
new table will be named 

59
00:04:09.933 --> 00:04:13.433 align:middle line:90%
highchol and should include 
only the rows for patients with 

60
00:04:13.433 --> 00:04:20.399 align:middle line:90%
high cholesterol. I'll start by 
typing a DATA step, beginning 

61
00:04:20.400 --> 00:04:24.566 align:middle line:90%
with the keyword DATA. By the 
way, I've disabled the 

62
00:04:24.566 --> 00:04:27.332 align:middle line:90%
autocomplete feature to make it 
easier for you to see what I'm 

63
00:04:27.333 --> 00:04:30.366 align:middle line:90%
typing. You might choose to 
leave this feature enabled as 

64
00:04:30.366 --> 00:04:36.432 align:middle line:90%
you work. I specify the name of 
the new table, highchol, and 

65
00:04:36.433 --> 00:04:40.233 align:middle line:90%
end the statement with a 
semicolon. Next I type the SET 

66
00:04:40.233 --> 00:04:43.466 align:middle line:90%
statement, specifying the input 
source as the table 

67
00:04:43.466 --> 00:04:50.932 align:middle line:90%
sashelp.heart. I'll add a WHERE 
statement so that SAS subsets 

68
00:04:50.933 --> 00:04:53.699 align:middle line:90%
the data to include only those 
rows where the value for the 

69
00:04:53.700 --> 00:04:57.900 align:middle line:90%
column Chol_Status is "High." I 
need to be sure to match the 

70
00:04:57.900 --> 00:05:00.633 align:middle line:90%
case for this value to the 
mixed case that is used in this 

71
00:05:00.633 --> 00:05:04.333 align:middle line:90%
column of the table. I'll 
complete the program with a RUN 

72
00:05:04.333 --> 00:05:07.933 align:middle line:90%
statement. Just to be sure that 
my syntax is correct, I'm going 

73
00:05:07.933 --> 00:05:10.233 align:middle line:90%
to check that each statement in 
the program ends with a 

74
00:05:10.233 --> 00:05:15.999 align:middle line:90%
semicolon. It's good to go. 
I'll submit the code and look 

75
00:05:16.000 --> 00:05:23.233 align:middle line:90%
at the log. SAS read 1791 
observations, or rows, from the 

76
00:05:23.233 --> 00:05:28.033 align:middle line:90%
table sashelp.heart and created 
the table highchol. There are 

77
00:05:28.033 --> 00:05:33.566 align:middle line:90%
no errors or warnings. Now I'll 
add a basic PROC PRINT step to 

78
00:05:33.566 --> 00:05:40.932 align:middle line:90%
generate a list report of the 
new table. I'll highlight this 

79
00:05:40.933 --> 00:05:47.899 align:middle line:90%
new code and click Run. I'll 
check the log to be sure that 

80
00:05:47.900 --> 00:05:53.533 align:middle line:90%
the code ran correctly and then 
I'll review the results. This 

81
00:05:53.533 --> 00:05:56.866 align:middle line:90%
basic PROC PRINT step displays 
all of the rows and columns in 

82
00:05:56.866 --> 00:05:59.999 align:middle line:90%
highchol, and you can see that 
it's a subset of the original 

83
00:06:00.000 --> 00:06:04.733 align:middle line:90%
table. In this video, you've 
learned to recognize the main 

84
00:06:04.733 --> 00:06:15.133 align:middle line:90%
components of SAS programs and 
how to write a basic SAS program. 

