Code
The saspy.sas_magic extension is already loaded. To reload it, use:
%reload_ext saspy.sas_magic
Simon Zhou
January 10, 2026
本 notebook 使用 Python Kernel + SASPy Magic 模式:
%%SAS magic 运行 SAS 代码pip install saspy如果看到 Java/IOM 错误,检查: - Workspace Server 是否运行: netstat -an | findstr "8591" - PATH 是否包含 sspiauth.dll - 或考虑使用 SAS Kernel: pip install sas_kernel && python -m sas_kernel.install --user
In this exercise, you’ll practice reading and exploring SAS built-in datasets.
The saspy.sas_magic extension is already loaded. To reload it, use:
%reload_ext saspy.sas_magic
Use PROC PRINT to display the first 10 observations from sashelp.class
Using SAS Config named: winlocal
SAS Connection established. Subprocess id is 32384
The SAS System
| Obs | Name | Sex | Age | Height | Weight |
|---|---|---|---|---|---|
| 1 | Alfred | M | 14 | 69.0 | 112.5 |
| 2 | Alice | F | 13 | 56.5 | 84.0 |
| 3 | Barbara | F | 13 | 65.3 | 98.0 |
| 4 | Carol | F | 14 | 62.8 | 102.5 |
| 5 | Henry | M | 14 | 63.5 | 102.5 |
| 6 | James | M | 12 | 57.3 | 83.0 |
| 7 | Jane | F | 12 | 59.8 | 84.5 |
| 8 | Janet | F | 15 | 62.5 | 112.5 |
| 9 | Jeffrey | M | 13 | 62.5 | 84.0 |
| 10 | John | M | 12 | 59.0 | 99.5 |
Use PROC CONTENTS to see the structure of sashelp.cars
The SAS System
The CONTENTS Procedure
| Data Set Name | SASHELP.CARS | Observations | 428 |
|---|---|---|---|
| Member Type | DATA | Variables | 15 |
| Engine | V9 | Indexes | 0 |
| Created | 11/08/2018 11:48:08 | Observation Length | 152 |
| Last Modified | 11/08/2018 11:48:08 | Deleted Observations | 0 |
| Protection | Compressed | NO | |
| Data Set Type | Sorted | YES | |
| Label | 2004 Car Data | ||
| Data Representation | WINDOWS_64 | ||
| Encoding | us-ascii ASCII (ANSI) |
| Engine/Host Dependent Information | |
|---|---|
| Data Set Page Size | 65536 |
| Number of Data Set Pages | 2 |
| First Data Page | 1 |
| Max Obs per Page | 430 |
| Obs in First Data Page | 413 |
| Number of Data Set Repairs | 0 |
| ExtendObsCounter | YES |
| Filename | C:\Program Files\SASHome\SASFoundation\9.4\core\sashelp\cars.sas7bdat |
| Release Created | 9.0401M6 |
| Host Created | X64_SR12R2 |
| Owner Name | BUILTIN\Administrators |
| File Size | 192KB |
| File Size (bytes) | 196608 |
| Alphabetic List of Variables and Attributes | |||||
|---|---|---|---|---|---|
| # | Variable | Type | Len | Format | Label |
| 9 | Cylinders | Num | 8 | ||
| 5 | DriveTrain | Char | 5 | ||
| 8 | EngineSize | Num | 8 | Engine Size (L) | |
| 10 | Horsepower | Num | 8 | ||
| 7 | Invoice | Num | 8 | DOLLAR8. | |
| 15 | Length | Num | 8 | Length (IN) | |
| 11 | MPG_City | Num | 8 | MPG (City) | |
| 12 | MPG_Highway | Num | 8 | MPG (Highway) | |
| 6 | MSRP | Num | 8 | DOLLAR8. | |
| 1 | Make | Char | 13 | ||
| 2 | Model | Char | 40 | ||
| 4 | Origin | Char | 6 | ||
| 3 | Type | Char | 8 | ||
| 13 | Weight | Num | 8 | Weight (LBS) | |
| 14 | Wheelbase | Num | 8 | Wheelbase (IN) | |
| Sort Information | |
|---|---|
| Sortedby | Make Type |
| Validated | YES |
| Character Set | ANSI |
Create a dataset called ‘students’ with columns: id, name, age, grade
The SAS System
| Obs | id | name | age | grade |
|---|---|---|---|---|
| 1 | 1 | Alice | 20 | 85 |
| 2 | 2 | Bob | 21 | 78 |
| 3 | 3 | Carol | 19 | 92 |
| 4 | 4 | David | 22 | 88 |
| 5 | 5 | Eve | 20 | 95 |
Calculate mean, min, max, and std for Age, Height, and Weight from sashelp.class
The SAS System
The MEANS Procedure
| Variable | Mean | Minimum | Maximum | Std Dev |
|---|---|---|---|---|
Age
Height
Weight
|
13.3157895
62.3368421
100.0263158
|
11.0000000
51.3000000
50.5000000
|
16.0000000
72.0000000
150.0000000
|
1.4926722
5.1270752
22.7739335
|
Create a frequency table for the Sex variable in sashelp.class
Write your observations here: - What did you learn? - What was challenging? - Questions for review?