没有合适的资源?快使用搜索试试~ 我知道了~
SAS Coursera Note
需积分: 0 0 下载量 2 浏览量
2023-01-20
21:43:32
上传
评论 1
收藏 3.93MB PDF 举报
温馨提示
试读
42页
SAS Coursera Note
资源推荐
资源详情
资源评论
{{renderer :tocgen}}
Link: [[SAS- Doing More with SAS]]
1. Essentials
Understanding SAS syntax
SAS 由若⼲step组成,其可以是proc 或 data 之⼀;
每⼀个step中会有若⼲命令,每⼀项命令要以分号结尾;
每⼀个step最后需要由⼀个run命令来运⾏;
还有⼀些命令是全局的,这些命令不需要run语句;
SAS语⾔不区分⼤⼩写;
SAS的注释为 * 或 /**/
2. Accessing Data
Understanding SAS Data
Types of Data
Structured data (e.g. xslx, etc.)
Unstructured data (e.g. .json, .txt, etc.)
What is a SAS table?
Required Column Attributes for SAS Tables
Name
1~32 characters
starts with letter or underscore
continues with letters, #, _
uppercase, lowercase, mixed case
Type
Numeric
0~9
minus sign
decimal point
scientific notation (E)
Character
letters
numbers
special characters
blanks
SAS Dates
01Jan1960=0
Length
Numeric: 8 types
Character: 1~32,767 bytes
Listing Table and Column Attributes
Accessing Data Through Libraries
Accessing Data in a Program
SAS library
Using a Library to Read SAS data
SAS library
a collection of data files that are the same type and in the same location. (location
+ type of file)
LIBNAME libref engine "path"
libref
name of the library
no more than 8 char
engine
base (SAS), excel, teradata, etc.
"path"
libref.table_name
read the file in the library
Although the libref might be deleted after SAS shuts down, the data is not deleted.
Automatic SAS Libraries
Work
Temporary
contents deleted at the end of SAS session
default library
if you don't type a libref in front of a table name, SAS uses the work library
These code snippets both refer to a temporary table named "Test" in work
library:
SAShelp
includes sample data
Demo: Exploring Auto SAS Libraries
There are two table: class_1 (in work library) and class_2 (in out library)
If SAS restarts, both class_1 and class_2 can not be found. However, class_1 is released
and cannot be retreated anymore. class_2, on the other hand, is still properly stored in
the system, and if we reload the out library, we will find the class_2 file again.
Using a Library to Read Other File Types
Excel work book is a collection of tables, each worksheets is one table.
proc contents data = mylib.class;
run;
data=work.test
data=test
libname out "s:/workshop/output";
data class_1 out.class_2;
set sashelp.class;
run;
options validvarname=v7;
libname xlclass xlsx "s:/data/class.xlsx";
proc contents data=xlclass.class_birthdate;
run;
libname xlclass clear;
LIBNAME libref XLSX "path/file_name.xlsx
OPTIONS statement;
OPTIONS VALIDVARNAME=V7
Force the column names in excel to available formats of SAS(version 7).
LIBNAME libref CLEAR;
Demo: Using a Library to Read Excel Files
Importing Data into SAS
Importing Unstructured Data
import wizards
PROC IMPORT
-
Demo: Importing a CSV File
3. Exploring & Validating Data
Exploring Data
options validvarname=v7;
libname xlstorm xlsx "s:/data/storm.xslx";
proc contents data=xlstorm.storm_summary;
run;
libname xlstorm clear;
PROC IMPORT DATAFILE="path/filename"
DBMS=filetype
! ! ! ! ! !OUT=output_table //library and name of the sas table
! ! ! ! ! !<REPLACE>; //overwrite the SAS output if alread exists
! ! ! ! ! !<GUESSINGROW=n/*or*/MAX;> //define the rows to scan at
the beginning for initialization
RUN;
proc import datafile="s:/data/storm.csv"
dbms=csv
out=storm_table
! ! replace;
run;
proc contents data=storm_table ;
run;
Exploring Data with Procedures
PRINT
create a listing of all rows and columns in the data
MEANS
calculate simple summary statistics
UNIVARIATE
include more details statistics related to distribution
FREQ
create a frequency table
Demo: Exploring Data with SAS Procedures
proc print data=pg.storm (obs=10); /*list first 10 rows*/
var Season Name /*...*/ ; /*var is to specify the variables
interested*/
! !/*can also added by dragging*/
run;
proc means data=pg.storm ;
var MaxWindMPH ; /*var in proc means should be numeric*/
run;
proc univariate data=pg.storm;
var MaxWindMPH;
run;
剩余41页未读,继续阅读
资源评论
LeonMichaelX
- 粉丝: 12
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功