basic course-demo-sas
SAS学习讲座第01节 SAS介绍及基础

一、SAS介绍1.SAS软件是由SAS公司开发的集数据仓库、大规模数据处理、数据挖掘、统计分析、图表制作、网页连接等为一体的计算机软体系统。
SAS是专业的统计分析软件,它对表格数据进行操作和统计分析比用Matlab更方便更专业。
2.SAS, SPSS, EXCEL 区别都能用于处理数据和统计分析,高级程度:SAS > SPSS > EXCELEXCEL一一侧重表格(办公),只能处理一些简单的数据分析,公式丰富,一般多用于计算(统计分析结果不全面);SPSS——专业统计分析软件,界面菜单式操作,简单易学,缺点是通用性不好(处理同样的数据,也要重复点菜单);SAS一一更专业统计分析软件,代码编程实现(通用性好),大多用于金融、医药等领域,用于大企业的数据分析,缺点是较难学。
3.要学好SAS,也离不开《统计学》。
现在是大数据时代,数据挖掘、数据库维护、做数据分析,在第一时间内获得或者找到最有价值的信息和资源,成为正确决策的依据, 这对金融、保险、医药、政府等企业和部门都至关重要。
SAS学习者的就业方向有:金融,银行、保险,证券、投行、临床研究,医药开发,市场调查,政府监管和教育研究部门。
5.我适合学SAS吗?学习SAS需要懂高等数学和统计学吗?实际情况是,任何专业背景的人,都可以学习并掌握SAS, 一经学会,终生受用。
不少人听说SAS是个统计分析软件,就自认为需要懂得高深数学和统计学的人才能学习,其实这是一个误区。
SAS在创办起,其宗旨是着重于80%工作量的统计分析前的数据处理,至于统计分析一旦数据就绪,通过相应的分析模块,几乎象傻瓜相机一样,谁都可以操作运行。
如果需要的统计方法学上提高或突破,恐怕不是统计分析的日常工作,而是统计方法学的科研了。
可见学习SAS不需要具备高等数学和统计学基础,只是需要有一般逻辑思维训练基础即可。
所以,只要遵循正确的学习道路并且获得有效的指导,就可以掌握扎实的SAS编程技能和技巧,再经过一定的经验积累,您也可以成为SAS行家里手,一直有许多学中(西)医、MBA、计算机、信息管理、经济(金融)、机械自动化,甚至英语专业的朋友成功转行SAS的例子。
SAS_Basic7

需掌握的要点
• Format在使用之前需先定义 (PROC FORMAT). • FORMAT 语句可应用定义的format. • 数据步里的Label 和 format 语句可用于其 后的 PROCs • 过程步里面的Label 和 format 语句只能用 于该过程步 PROC本身
为网络或Word/Excel文件创建HTML 表 ODS LISTING CLOSE; ODS HTML FILE='educ.html'; PROC FREQ DATA=tdata ; TABLES educ; FORMAT educ educ.; TITLE 'HTML Output From PROC FREQ'; RUN; ODS HTML CLOSE;
Program 6
PROC FORMAT; ...
DATA tdata ; INFILE 'd:\data\tomhs3.dat'; INPUT ptid $ clinic $ group sex educ eversmk alcbl sebl_1 sebl_6 ; run;
LABEL LABEL LABEL LABEL LABEL LABEL LABEL clinic = group = educ = sebl_1 = sebl_6 = alcbl = eversmk 'Clinical Center'; 'Drug Treatment Group'; 'Highest Education Attained'; 'Patient Report Drowsiness'; 'Patient Report Headaches'; 'Alcoholic Drinks Per Week'; = 'Ever Smoke Cigarettes';
SAS编程基础..

TANGJIE
2 35 169.2 60.8
GAOJUN
2 24 176.0 73.3
SUNHONG 2 27 158.3 49.9
;
PROC MEANS;
CLASS SEX;
VAR HEIGHT WEIGHT;
RUN;
❖ DATA STEP(数据步)
以DATA语句开始 将数据读入SAS系统,建立SAS数据集
INPUT NAME $ V1 V2 V3 V4 V5 V6;
可以写成:
INPUT NAME $ V1-V6;
注意: 字符型变量NAME不包含在这个缩写清单中。 这些变量要求类型相同,或全是数值型的或全是字 符型的。
v1 1-2 v2 3-4 v3 5-6 可表示为(v1-v3)(3*2.) 或(v1-v3)(2.2.2.) 表示共有三个变量,每个变量有两位数据
观测(Observation,OBS)
描述被观测对象的单一整体(如一个人、 一个实验动物等)某些所研究特性的一系列数 据值称为一个观测,又称观察。在SAS数据集 中每一行数据是一个观测。
变量(Variable)
变量指定了数据的某一特性。在SAS数据 集中,每一个观测是由各个变量的数据值组成。 在数据集中每一列数据是一个变量。
三、SAS语句
SAS语句是由SAS关键词<操作数><选择项> 组成,以分号(;)结束 1、语句格式:关键词<操作数><选择项> 例: data one two (keep=x);
2、SAS语句的类型 可执行语句(X)例:PUT,IF,BY等 定位语句(P)例:DATA等 说明语句(D)例:LABEL等
回到程序编辑窗口,修改源程序,再执行 如果程序编辑窗口没有显示刚刚执行的程序,
sas软件教程精华

机器学习算法
SAS支持多种机器学习算法,包括线性回归、逻辑回归、决策 树、随机森林等,用户可以根据自己的需求选择合适的算法。
06
sas应用场景
金融行业
风险管理
SAS提供强大的统计分析功能,帮助金融行业进行风险评估、模型 开发和管理,从而提高风险控制水平。
信贷评估
通过SAS的数据挖掘和机器学习算法,金融机构可以对客户进行精 准的信贷评估,降低信贷风险。
预测性分析在SAS中的实现
使用PROC REG过程进行线性回归分析;使用PROC ARIMA过程进行时间序列 分析。
04
可视化报告
图表类型
柱状图
用于比较不同类别的数据,直观展示各组之 间的差异。
折线图
用于展示数据随时间变化的趋势,帮助理解 数据的变化规律。
饼图
用于表示各部分在整体中所占的比例,方便 比较不同部分的大小。
03
过程步可以读取数据集、输出数据集、生成报表或图形,并支持自定 义过程和宏程序等扩展功能。
04
过程步还支持使用嵌套过程,以实现更复杂的分析任务。
宏语言
宏语言是SAS中用于编写 可重用代码的一种编程语 言,它允许用户定义自己 的程序和过程。
宏语言可以用于简化重复 性任务、封装复杂逻辑和 创建自定义过程等。
文本挖掘应用
文本挖掘在很多领域都有应用,如信息检索、舆情分析、品牌监测等。
机器学习
机器学习概念
机器学习是人工智能的一个子领域,它使用计算机算法让 机器从数据中学习并改进自身的性能。
SAS机器学习工具
SAS提供了一整套机器学习工具,包括Predictive Analytics、 SAS/ML等,这些工具可以帮助用户进行机器学习的全过程,
SAS课件——第二章SASBase

第二章SAS软件的BASE(数据库功能)第一节简介Base SAS软件是SAS系统的基础和核心。
主要功能是数据管理和数据加工处理,并有报表生成和描述统计的功能,管理用户使用环境,进行用户语言的处理,调用其他SAS模块和产品。
Base SAS软件可以单独使用,SAS其他软件产品以它为基础实现功能。
提供以下几方面功能:一、数据管理功能1、信息存储和检索2、数据修改与程序设计3、文件操作二、基础统计计算功能Base SAS软件中有一些基本过程和SAS函数能够完成基础统计计算。
它包括:1、计算简单描述统计量2、对数据进行标准化、求秩以及有关统计量3、生成并分析列联表4、计算概率分布函数、分位数、样本统计量以及产生随机数三、报表生成和图形显示功能Base SAS软件输出数据与读入数据时同样可以采用任何格式。
除了SAS过程产生的固定格式的报表外,用户可根据自己的需要来设计报表的输出格式,包括输出文件到磁盘上。
SAS的一些基本过程可绘制水平的或垂直的直方图、饼图、块图和星形图,分布图、曲线图、时间序列图等等。
四、SAS数据集的结构SAS数据集是关系型的,它通常分为两部分:●描述部分——包含了一些关于数据属性的信息●数据部分——包括数据值SAS的数据值被安排在一个矩阵式的表状结构中,见图3-1所示。
●表的列称之为变量(Variable),变量类似于其它文件类型的域或字段(Field);●表的行称之为观察(Observation),观察相当于记录(Record)。
图3-1 一个SAS数据文件输入和输出格式SAS数据集的数据值的内部存放格式并不一定与该数据值的输入和输出格式一致,这取决于SAS的两个重要功能:输入格式(Informats)和输出格式(Formats)。
输入格式指示SAS系统如何读入数据,而输出格式指示SAS系统如何输出数据。
它们的一般形式如下:●输入格式:<$>informat<w>.<d>●输出格式:<$>format<w>.<d>其中$符号指示这是个字符输入输出格式,没有$符号表示是数值输入输出格式;Informat是一个输入格式的名字,format是一个输出格式的名字;w是宽度值,对许多输入输出格式这个值是输入输出数据的列数;d在数值输入输出格式中是小数部分的长度;点”.”是所有输入输出格式中必须包含的分隔符,作为名字的一部分。
sas课程设计代码

sas课程设计代码一、教学目标本课程的教学目标是使学生掌握SAS编程的基础知识,能够熟练使用SAS软件进行数据分析。
具体包括以下三个方面的目标:知识目标:学生需要掌握SAS的基本语法、数据管理、统计分析等基础知识。
技能目标:学生能够熟练使用SAS软件进行数据导入、数据清洗、数据分析等操作,并能够根据实际问题选择合适的统计方法。
情感态度价值观目标:培养学生对数据分析的兴趣,使其认识到数据分析在解决问题中的重要性,培养学生的创新意识和团队合作精神。
二、教学内容本课程的教学内容主要包括SAS的基本语法、数据管理、统计分析等方面。
具体安排如下:第一章:SAS基础语法,包括SAS的数据类型、变量定义、表达式等。
第二章:数据管理,包括数据导入、数据清洗、数据排序等操作。
第三章:统计分析,包括描述性统计、推断性统计、回归分析等方法。
第四章:SAS编程进阶,包括宏编程、SQL编程等高级操作。
三、教学方法为了提高学生的学习兴趣和主动性,本课程将采用多种教学方法,包括讲授法、讨论法、案例分析法、实验法等。
讲授法:用于向学生传授SAS的基本语法和统计方法。
讨论法:用于引导学生探讨实际问题,培养学生的创新意识和团队合作精神。
案例分析法:通过分析实际案例,让学生学会如何使用SAS解决实际问题。
实验法:通过实验操作,让学生熟练掌握SAS软件的使用。
四、教学资源为了支持教学内容和教学方法的实施,我们将选择和准备以下教学资源:教材:《SAS编程基础》参考书:《SAS高级编程》多媒体资料:教学PPT、视频教程实验设备:计算机、SAS软件五、教学评估为了全面、客观、公正地评估学生的学习成果,本课程将采用以下评估方式:平时表现:通过观察学生在课堂上的参与度、提问回答等情况,评估学生的学习态度和理解程度。
作业:布置适量的作业,让学生巩固所学知识,通过批改作业了解学生的掌握情况。
考试:进行期中考试和期末考试,全面测试学生对SAS基础知识和技能的掌握。
Basic_course_shortcut

Basic Computer T raining Course (Designed for the school teachers of BCICT Programme implemented Schools)This book covers the following courses:✓Introduction to computer ✓Computer History✓Windows OS✓MS-Word 2000/XP✓MS-Excel 2000/XP✓MS-Power Point 2000/XP ✓MS-Access 2000/XP ✓Adobe PageMaker 6.5/7.0 ✓Q-Basic✓Multimedia Overview✓E-mail & Internet✓Virus Scanning✓Basic HardwareIntroduction to computer [ 4 hours ]What is computer?HardwareSoftwareUserData administrator, Data Entry Operator, Desktop Publisher, Designer and Developer etc.Sof tw ar e T y pe sSystem Software, Application Software, Utilities SoftwareComputers: History and DevelopmentOverviewEarly Computing Machines and InventorsGenerations of Modern ComputersFirst Generation (1945-1956)Second Generation Computers (1956-1963)Third Generation Computers (1964-1971)Fourth Generation (1971-Present)Fifth Generation (Present and Beyond)Types of Computer∙According to sizeSuper computer, Mainframe computer, Mini computer, Micro computerDesktop: , Laptop:∙According to functionAnalogue Computer, Digital Computer, Hybrid ComputerComputer System [ 4 hours ]1. Input Unit2. Processing UnitALU: Arithmetic and Logic UnitCU: Control UnitMU: Memory UnitThere are two types of memory∙Primary Memory : RAM, ROM∙Secondary Memory : Hard Disk, Floppy Disk, Compact Disk, Zip Disk3. Output Unit0Monitor, Printer0Binary Language0Binary Digit (BIT)0Bits and BytesPeripherals of Computer (Hardware of PC)Computer StartingShutting Down the computerOperating SystemsMS-DOS [ 6 hours ]Types of booting:Files, Filename, Extension, Directory, DOS Prompt, DOS CommandMicrosoft ®Windows Operating System [ 10 hours ] To find a file or folderLocking/unlocking the taskbarMoving the taskbarResizing the taskbarChanging the properties of the taskbarPlacing Toolbar to the TaskbarCreating new folder on the desktopTo change the name of folderTo open the folderTo delete the folderTo undelete the deleted itemsTo copy files from one folder to another folderTo copy file or folder by mouse.To move file or folder by mouse.Arranging your desktop icons.Creating desktop shortcutsTo create a program folder and put program items on itRemoving items from the start menuTo place wallpaperTo put screensaverRight-click on empty desktop > click properties > click screensaver tabTo change the appearance of windowsWindows Explorer-Open Windows-Explore Windowso Create new folder-Edit (Cut, Copy, Paste Selection, undo)-View-Go-Tools (Find)-HelpStart Menu-Shut Down-Log off-Run-Setting (Task and Start Menu)-Program (Start up, A accessories, Paint, Word pad, calculation0-Documents (Recent Document)Microsoft Word [ 20 hours ]Create new file, open an exiting file, save file, import and export a saved file.Help to set page margin, paragraphs and sections within a document,Adjust indents and hanging indents,Add bulleted and numbered lists,Change the fonts, font styles and font size according to our wish,Edit text by inserting, deleting, moving and coping passages of text,View document changing in different size,Set tab stops and select different types of tabs,Create and edit tabular information,Set tabs for dot leaders,Find specified text and replace one text using with anotherInsert page breaks, page numbers, reference points, special symbols, date and time in a document and equation, etc.Insert header (top of the document), footer (bottom of the document) and annotation, etc, Insert frames for sidebars, run-arounds and other special effects,Create and edit columnar information (i.e. column),Create and insert pictures using the drawing toolbar,Check spelling, thesaurus, and grammar,Sort text and hyphenation,Create and edit Excel Worksheets,Automate our work by recording and playing macros andPrint document and envelopes.How to enter Microsoft word?SOME SHORT CUT KEYSHow to move CURSOR?What is highlighting?How to highlighting text-using Cursor?How to highlight text-using mouse?How to delete text?How to save document?FileNew, Open, Close; Save, Save As; Page Setup, Print Preview, Print.EditUndo, Redo, Cut, Copy, Paste, Find, Replace, Go to.View:Normal, Web Layout, Print Layout; Toolbar, Ruler, Document Map, Header and Footer, Footnote, Zoom.InsertBreaking page /column, Inserting page number, Inserting date/ time, Creating auto text, Inserting auto text, Inserting symbol, Inserting footnote /endnote, Inserting clip art picture, Inserting picture from file, Inserting auto shapes, Inserting Word art, Inserting chart, Wrapping text around the picture, Inserting text boxFormatFont, Paragraph, Bullet and Numbering, Boarder and Shading; Column, Tab, Drop Cap, Text Direction, Change Case, Style.ToolsSpelling and gummer, Language, Word Count, Auto Correct, Protect Document, Mail Merge, Macro, Customize, OptionTableDraw Table, Insert, Delete, Select, Merging cell, Splitting Cell, Splitting Table, Table Auto Format, Auto Fit, Heading Row Repeat, Convert, Sort, Formula, Table Property.WindowNew Window, Arrange All, Split, Change File.HelpMicrosoft Word Help, What's This.=THE END=Microsoft Excel [ 10 hours ]Entering ExcelSome useful terms* Multiplication / Division + Addition - Subtract > Greater than< Less than >= Greater than equal to <= Less than equal toEntering DateCreate a new Workbook.Saving, Opening, Closing, RE-saving, Page Setting, Previewing the documents Copying, Moving, finding, replacing the data: Creating serial numberDeleting DataDeleting the worksheetMoving data from one book to another book or form one sheet to another sheetAdding header/footerInserting cells, rows, columns or worksheet Inserting chart:Breaking page:Using functionInserting pictureChanging number formatArranging dataChanging font, font’s style and fonts size Adding border and shadingChanging width and height of rows and columns Note:Hiding or displaying rows or columns or sheet Changing sheet nameInserting background pictureApply auto format to worksheetDisplaying or hiding gridlinesSorting data in ascending or descending order Filtering dataFromSubtotalsConverting text into columnHow to do page set upHow to print preview:How to view formula bar:Splitting windowsFreezing windows=THE END=MS POWERPOINT [ 6 hours ]Duplicating Slide Deleting SlideSlide ShowInserting new slide Slide NumberMovies and Sound: Slide LayoutSlide color Scheme Adding Background Apply Design Template Color and lineView ShowRehearse and TimingPresent animationCustom AnimationSlide sorterSlide notesSlides miniatureSlide masterChange caseSlide transition= The End =Access 2000/XP [ 6 hours]-Introduction of Access-Introduction of Database-Types of Database-DBMS-RDBMS-Data Types-Rules to Declare Data types -Creating Tables-Design View-Wizard View-Entering data view-Creating Form-Design View-Wizard View-Creating Report-Design View-Wizard viewCreating Pages of database for web-Design View-Wizard View-Existing ViewCreating Queries-Design View-Wizard ViewModule DescriptionCreating Functions-user defined-Built In functionsMacros DescriptionsCreating Relationship-One to One Relationship-Many to many relationship-One to Many RelationshipSecurity for Database-Creating user-Set Database Password-User & user Permit ion-Deleting user and Database PasswordQBasic Programming [ 10 hours ] -Introduction of QBasic Programming-Basic terms used in QBasic-Basic Statement and CommandsVariables-Declaring variable-Types of variablesOperators-Arithmetic Operators-Conditional Operators-Logical OperatorsBasic Programs-INPUT-PRINTLooping for Programs-For Loops-While loops-Inner loops-Outer loopsFunctions-Built in Functions-User Defined functionsArray-Singular Array-Double Array-Multidimensional ArrayAdobe PageMaker 6.5 [ 6 hours ]IntroductionTo start PageMakerTo work with PageMaker Changing the PageMaker’s view Revert:Document setupPrintPreferencePaste multipleEdit storyGo to pageInsert pagesRemove pagesSort pagesGo Back / ForwardColumn guidesTo change fontTo change font sizeTo change line spacing [leading] To change type styleTo change export tracking Horizontal scaleCharacterParagraphFillStrokeFill & strokeArrangeText wrapGroupUngroupLock / unlock positionMaskUnmaskPolygon settingsHiding or displaying rulersSetting zero lock on or offLocking or unlocking guidesApplying bullets and numberingChanging caseAdding drop capSetting indentsApplying rounded corner=THE END=Using Windows Media Player [ 2 hours ] Windows Media Player play commands∙Play/Pause /Stop∙Skip Back∙Skip Forward∙Rewind (available for video files in Windows Media Format only)∙Fast Forward (available for video files in Windows Media Format only) ∙Shuffle/Repeat∙VolumeCopying and playing CDsPlaying music from CDsViewing album detailsTo create your own CDUnderstanding the CD Audio featureAdding files to Media LibraryTo create a playlistTo add a file to a playlistTo delete an individual item from Media LibraryTo delete a playlist from Media LibraryTo restore an individual item in Media LibraryTo permanently delete playlist from Media Library and computer==The end==INTERNET AND E-MAIL [ 4 hours ]InternetWhat is internet?Requirement To Access InternetSteps of surfing the net:-Favoriteso Add to favoriteso Organize favoriteso Internet option-Viewo Tool baro Text sizeo SourceE-mail:What is email?Advantages of e-mailInternet Mai(Hotmail, Yahoo, Rediff etc)Email (pop)-Set up new account-Identity Management and Creation-Import mails from backup-Edit-View-Toolso Send and receiveo Address Booko Message ruleso Accounto Option-Messageo New Messageo Reply to sendero Block sender-Create folder at local mails== The end==COMPUTER VIRUS [ 2 hours ] Types of Computer Viruses:✓Boot Sector Viruses ✓Source code viruses ✓File Viruses✓Visual Basic Worms ✓Polymorphic Viruses ✓Macro Virus✓Batch file virus✓Companion viruses ✓Macro viruses ✓System Sector Viruses ✓File Viruses✓Macro Viruses✓Companion Viruses ✓Cluster Viruses✓Batch File Viruses✓Source Code Viruses ✓Visual Basic WormsScanning and Removing virus"The End"Basic Computer Hardware [ 30 hours ]1.Main Parts of Computer(A)Mother Board1. ISA Mother Board,2. PCI Board(B)CPU(C)Computer Memory1) Main Memory(a) RAM (Random access memory), (b) ROM (Read only memory)2) Auxiliary Storage(a) Floppy Disk, (b) Hard Disk, (c) Compact Disk etc.(D)Power Supply(E)Cards (Types of Card : ISA, PCI, AGP)1. IO Card,2. Display Card,3. Sound Card,4. Modem,5. Network (LAN) Card,6. TV Tuner Card etc.(F)Input Device1. Keyboard,2. Mouse,3. Scanner,4. Light Pen,5. Joystick etc.(G)Output Device1) Soft output deviceMonitor2) Hard output unitPrinters(a) Impact Printers(b) Non-impact Printerputer Assembling3.Software Installation(A)Operating System Installation(B)Application Software Installation, Manage Software.(C)Driver Software Installation4.Troubleshootingworkingputer Maintenance Tools(Software CD, Driver CD, Screw Driver Etc.)。
如何使用SAS进行数据分析和建模的教程

如何使用SAS进行数据分析和建模的教程一、SAS的简介及基本操作SAS(Statistical Analysis System)是一款强大的统计分析软件,被广泛应用于各个领域的数据分析和建模中。
下面将介绍SAS的简单操作流程。
1. 安装和启动SAS:根据官方指南,下载并安装SAS软件。
启动SAS后,会出现主界面,包括编辑窗口和日志窗口。
2. 导入数据:点击编辑窗口中的“Import Data”按钮,选择要导入的数据文件,并按照提示完成导入过程。
导入的数据可以是CSV、Excel等格式。
3. 数据探索:通过使用SAS的数据探索功能,可以查看数据的基本信息,如变量名、数据类型等。
点击编辑窗口中的“Explore Data”按钮,选择导入的数据文件,即可查看数据的摘要统计信息。
二、数据预处理在进行数据分析和建模之前,需要对原始数据进行预处理,以确保数据的质量和完整性。
1. 缺失值处理:SAS提供了多种处理缺失值的方法,如删除含有缺失值的观测样本、插补缺失值等。
通过使用SAS的函数和命令,可以快速处理数据中的缺失值。
2. 异常值处理:SAS可以通过绘制箱线图、散点图等图形,来检测和处理数据中的异常值。
针对异常值,可以选择删除、替换或者离群点处理。
3. 数据标准化:标准化数据可以使得不同变量之间具有可比性,常用的方法包括Z-score标准化、最大-最小标准化等。
在SAS中,可以使用相应的函数和过程来进行数据标准化。
三、探索性数据分析(EDA)探索性数据分析是数据分析的关键步骤之一,它旨在通过可视化和统计方法,了解数据的分布和关系,为后续建模做准备。
1. 描述性统计:使用SAS的summary、means等函数,可以计算数据的均值、方差、中位数等统计量,从而对数据进行初步的描述。
2. 可视化分析:SAS提供了多种绘图函数,如histogram、scatter plot等,可以绘制直方图、散点图等图形,来展示变量之间的关系和分布情况。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
SAS® Programming Introduction: BasicConcepts How-To DemonstrationsFor SAS 8 and SAS®9SAS® Programming Introduction: Basic Concepts e-CourseCopyright © 2009 NULL. All rights reserved. Printed in the United States of America. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, or otherwise, without the prior written permission of the publisher, SAS Institute Inc.Book code E1193, course code ECINTRO, prepared date 08Apr2009. ECINTRO_001For Your Information iii Table of ContentsLesson 1 Getting Started with SAS Programming ............................................. 1-1 Lesson 2 Understanding SAS Programming Basics ......................................... 2-1 Lesson 3 Navigating and Using the SAS Interface ............................................ 3-1 Lesson 4 Working with SAS Libraries, SAS Data Sets, and the ImportWizard 4-1Lesson 5 Using PROC PRINT to Create List Reports ........................................ 5-1 Lesson 6 Using PROC PRINT to Enhance List Reports .................................... 6-1 Lesson 7 Using the DATA Step to Read Raw Data ............................................. 7-1 Lesson 8 Using Assignment Statements to Create Variables ........................... 8-1 Lesson 9 Using Conditional Logic ...................................................................... 9-1 Lesson 10 Using PROC MEANS to Create Summary Reports .......................... 10-1 Lesson 11 Using PROC FREQ to Create Frequency Reports ........................... 11-1iv For Your InformationLesson 1 Getting Started with SAS ProgrammingReading the Survey Data and Creating Reports82 1.View the data and figure out the layout of the data file.2.Read the data into SAS.3.Create your reports.1. View a copy of the survey form.2. View the survey.dat plain text file in a text editor to determine the layout of the data file.3. Write a SAS program to read the data.4. Submit the program.5. View the log to ensure that the program read the data into SAS successfully.6. Add a statement to the program to print the data.7. Submit the program.8. View the report.9. Alter the program to find the number and percentage of male and female survey respondents.10. Submit the program.11. View the report.12. Alter the program to find the states in which the respondents live.13. Submit the program.14. View the report.15. Alter the program to find the average number of years that respondents worked for their presentemployers.16. Submit the program.View the report.Touring Sample SAS Reports901. Open SAS.2. Submit the program to create the following reports:- Listing report of the survey data- Listing report of the survey data with the values in the column Profession changed to R and D for G and to Executive for A; the state name spelled out; the codes F and Mchanged to Female and Male; and the report grouped by gender-Listing report of the survey data distributed by gender and broken out by state-Listing report of the survey data distributed by state-Summary statistics of the survey data-Advanced statistics of the survey data inclidng the mean number of years with anemployer, median, mode, and extreme observations3. View the columns of the listing report. Notice the values for the column Profession.4. View the second report. Notice the values for Profession, the values for Executive, andthe state name. Also notice that the listing report is grouped by gender.5. View the third report. Note the number of females and males and the custom note in the title.6. In this report, what percentage of Gender is female? 52.3%7. View the fourth report. Notice the distribution by state of birth.8. In this report, which state represents the highest percentage of the total? North CarolinaNine individuals come from North Carolina, making up 42.86% of our data.9. View the fifth report. Notice the mean, or average, number of years with thepresent employer.10. Which profession has the lowest mean number of years with the present employer?Executives The average number of years with the present employer is 1.33 forexecutives.11. View the sixth report. Notice the mean number of years with an employer.12 Scroll forward in the report. Notice the extreme observations with the five lowest andfive highest values in the data.13. Look at the list of lowest values. How many individuals in the data have the lowestnumber of years of service? Four14. Submit a program to produce the following charts:-Distribution of Gender-Total Number of Years at Present Employer by State-Frequency of Profession-Frequency of Gende r-Map – Number of Students per State-Listing Report in HTML-Frequency – Distribution of States in HTML-Frequency – Distribution of States in a Bar graph15. View the first chart. Notice the distribution of gender in the horizontal bar chart.16. View the second chart. Notice the sum of years with a present employer for each state.17. View the third chart.18. View the fourth chart. Note that the chart is broken out by gender and broken out by state.19. What is the frequency count for males from Pennsylvania? One20. View the fifth chart. Notice that the height of the state indicates the frequency count.21. How many respondents are from Florida? One22. View the sixth chart. Notice that this is the same listing report as previously viewed inHTML format.23. View the seventh chart.24. View the eigth chart. Notice that this report appears color coded with the state on oneaxis and gender on the other axis. Notice that when the mouse hovers over one of the bars, the values for the bar appear.Lesson 2 Understanding SAS Programming BasicsLesson 2: Understanding SAS Programming BasicsCreating and Locating Course Practice Files441.Open the zip file containing the course practice files.2.Extract the files to your My Documents\My SAS Files folder.3.Verify that all the practice files were extracted correctly.This demonstration shows you how to create and locate practice files for this course in the Windows file system.Put the zip file on your desktop.1. Now we need to perform a critical task for using this course: creating and locating the practice filesyou’ll use for SAS programming throughout the course. If you’re not familiar with extracting files from a ZIP file, pay close attention to this demonstration and feel free to play it over. But don’t worry — you’ll get step-by-step instructions in the upcoming practice.2. Open SASIntro.zip file in WinZip.3. Extract the files to My Documents . Make sure the Use Folder Names option is selected.4. WinZip opens the MyDocuments\My SAS Files\SASIntro folder. Double-click PracticeFiles .5. Notice that there are .dat files as well as SAS files.6. Notice the .sas7bdat extension, which indicates a SAS data set.For information about other operating environments, see Creating and Locating Course Practice Files in Appendix C or D .Viewing a Raw Data File83This demonstration shows you how to view the raw data file pilot dot dat.Put pilot.dat in MyDocuments\My SAS Files\SASIntro\PracticeFiles1.In Windows Explorer, verify that the MyDocuments\My SAS Files\SASIntro\PracticeFiles folderis open.2.Double-click Pilot.dat.3.Examine the raw data file in WordPad. Notice that the file contains only data, and that some of thecolumns look run together. For example, there appears to be a column of first names but it has some other column or columns immediately to its left. Other columns look freestanding.For information about other operating environments, see Opening Raw Data Files in Appendix C or D.Opening and Viewing a SAS Data Set125This demonstration shows you how to open and view a SAS data set.Put pilotdata.sas7bdat in your Work folder.1.Open Work.Pilotdata in SAS.2.Examine the data portion of the Pilotdata data set in SAS. There are 6 columns. Scroll down to seethat there are 50 observations, and then scroll back up.3.What is the value for the variable LastName in observation 20? It is ECHOLS.4.You can view the column attributes individually for each variable. For example, this is the ColumnAttributes window for the variable LastName.5.Open the Properties window for the data set. Examine the General tab, the Details tab, and theColumns tab.For information about other operating environments, see Opening SAS Program Files in Appendix C or D.Opening and Viewing a SAS Program File135This demonstration shows you how to open and view a SAS program file.Put pilot.sas on your desktop.1.Right-click pilot.sas and select Open With, and then WordPad to open the file in WordPad. Notice that the file contains only SAS programming statements, not any other formatting. Only the indention is preserved.Lesson 3 Navigating and Using the SAS InterfaceStarting SAS48This demonstration shows you how to start a SAS session.1. Double-click the desktop icon for SAS. When SAS opens, we see the interactivewindowing environment. Notice the Results and Explorer windows on the left and the Log and Editor windows on the right.2. In the Log window, notice that there are some messages including copyright notes andthe version of SAS. One important piece of information is the site number. If you contact SAS technical support by telephone or Web site for assistance, SAS requests this site number.You might want to make a note of that number once you start SAS.3. What is the site number in the Log window shown here? It is 7857162208.Navigating SAS Windows and Exploring SAS Code Editors80This demonstration shows you how to navigate SAS windows and explores some editing features of the Editor and Program Editor windows.Make sure your Results formats are set to listing only.The program is m212_3_d.sas.Type this program into the Editor window and submit it.data survey;infile 'survey.dat';input Initials $ Gender $ State $ Years Profession $;run;proc print data=survey;var gender profession years;run;1.After the program runs, the Output window moves to the front.2.Now, let’s take a look at the code editors. Notice that the title bar is dimmed for an inactive window.Click the Editor window to activate it.3.The Editor window provides many features to make coding easier. Notice in this code that the SASprogram elements are color coded. To make your code easier to read, you can automatically indent the next line of your code when you press ENTER. You can view the overall flow of your SAS program or see each PROC and DATA set in detail. Just click the plus or minus icon.4.Close the Editor window by clicking the X in the top-right corner of the window.5.Open the Program Editor window by selecting ViewÖProgram Editor.6.Paste the same program here.7.You can set options to display line numbers or not, and you can toggle line numbers on and off.Using line numbers, we can edit code line by line. For example, we can type D to delete a line or I toinsert a line. Or we can type M to move a line, then type A or B on a line to indicate moving after or before that line.8.Close the Program Editor window and activate the Log window.9.Activate the Output window.10.Activate the Results window.11.Activate the Explorer window.Leave everything as is for the next practice.Issuing Commands98This demonstration shows you how to issue commands in different ways to clear the contents of your SAS windows.1.Our SAS programming windows still contain information from the previous demonstration, where wesubmitted a SAS program. Now we’ll see how to issue commands using the toolbar, the menus, and the command bar. SAS provides several different ways to handle most tasks, and the same is true for issuing commands.2.Activate the Editor window, and then the Log window, and then the Output window. To managethis information we might want to clear the contents of these windows periodically.3.Activate the Log window and click the New icon.4.Activate the Output window and click the New icon.5.Activate the Editor window and click the New icon.6.Activate the original Editor window.7.Select Edit Ö Clear All.8.Activate the new Editor window. Type this code:proc print data=survey;run;9.Then, type clear in the command bar and press ENTER.For information about other operating environments, see Issuing SAS Commands in Appendix C or D.Assigning Function Keys102This demonstration shows you how to assign function keys using the KEYS window.SAS assigns default function key settings, but you can easily add, edit, or delete them. Let’s use the KEYS window to assign a command to one of our function keys.1.Type keys in the command bar and press ENTER.2.Notice the two columns in the Keys window – the Key column and the Definition column.3.In the Definition column for the F-12 key, type clear. Then close the KEYS window to save thechange.4.Type keys in the command bar again. Verify that the new definition of F-12 has been saved. Closethe KEYS window.For information about other operating environments, see Issuing SAS Commands in Appendix C or D.Entering and Processing SAS Code117This demonstration shows you how to enter and submit a SAS program. Start with SAS windows cleared. As you learned earlier, you can use the Editor window or the Program Editor window to enter your programming code. Here we’ll use the Editor window.1. Type this program into the Editor window:data pilotdata;infile 'pilot.dat';input EmployeeID $ 1 - 6FirstName $ 7 - 19LastName $ 20 - 34JobCode $ 35 - 41Salary 42 – 47Category $ 48 - 50;run;proc print data=pilotdata;run;2. Zoom the Editor window to see the entire program.3. When you write SAS programs, you can enter code in free format. That is, SAS statementscan begin and end in any column, be on the same line as other statements, extend overseveral lines, can be in uppercase or lowercase. However, for readability, most SASprograms follow a suggested standard. Our program here follows the suggested standard.Notice that DATA, PROC, and RUN statements begin in or near column one; all otherstatements are indented by several columns for readability, a blank line separates steps, andonly one statement appears on a line.4. Look at the INPUT statement, which specifies the variables to create from the raw data file. This statement illustrates another suggested standard, which is to define each SAS variable on a separate line and to align the beginning and ending position numbers.5. Click the running man tool on the toolbar.6. Activate the Log window by clicking the Log button.7. Scroll down to review the log.Reviewing Results and Checking for Errors142This demonstration shows you how to review your program’s processing and check your code for errors.1.Start with the program from the previous demo on the Editor window and all other windows clear.2.Change the keyword for the INFILE statement to IN.3.Submit the program.4.Activate the log and notice the error message about the IN keyword.5.Scroll down in the log until you reach another error message about the INFILE statement.6.If SAS can figure out an error, it will try correcting it. For example, if we had specified I-N-F-L-I-Einstead of INFILE, SAS would make an educated guess, and then give us this warning: Assuming the symbol INFILE was misspelled as INFLIE.7.Next, notice the NOTE in blue saying that SAS stopped processing.Finally, notice the WARNING in green saying that the output data set might be incomplete.Modifying Code to Correct an Error153This demonstration shows you how to correct an error in a SAS program.Start with error message in the Log from the last demo.1. Clear the Log window.2. Clear the Editor window and paste in this code:data pilotdata;infile 'pilot.dat';input EmployeeID $ 1 - 6FirstName $ 7 - 19LastName $ 20 - 34JobCode $ 35 - 41Salary 42 - 47Category $ 48 - 50;run;3. Add a pound sign to the EmployeeID variable, and submit the program.4. Check the SAS Log and notice the error messages, the note, and the warning.5. In the Editor window, fix the error and resubmit the program.6. Check the Log again.7. Clear the Log window.For information about other operating environments, see Recalling and Modifying SAS Program Code in Appendix C or D.Saving and Retrieving SAS Code173This demonstration shows you how to save and how to retrieve a SAS program.Start from the ending state of the last demo, with the Log window activated.1.Activate the Editor window.2.Select File Ö Save As, and then select \My SAS Files\SASIntro\PracticeFiles, type the namepilotdata.sas, and click Save.For information about other operating environments, see Saving and Retrieving SAS Code in Appendix C or D.Lesson 4 Working with SAS Libraries, SAS Data Sets, and the Import WizardViewing the Contents of SAS Libraries56This demonstration shows you how to view SAS libraries and their contents using the Explorer window. Have the Cargorev and Pilotdata data sets in your Sasuser library. Move other files (except Profile catalogs) out of Sasuser for the moment.1.Activate the Explorer window. If the Explorer window isn’t open in your SAS windowingenvironment, you can display the window by selecting View ÖExplorer.2.In the Explorer window, double-lick Libraries. Select the view menu to see the various displayoptions such as large icons, small icons, or detailed list.3.Double-click the Work library. Notice that it is empty. Click the Up One Level tool.4.Double-click Sasuser. You see two data sets: Cargorev and Pilotdata. (You might have other datasets in your Sasuser library.)5.Notice the Profile catalog in Sasuser.6.Double-click Cargorev to view the data it contains.7.Right-click the Cargorec data set icon and select Properties from the menu. Notice that the data setcontains 50 rows and 4 columns.8.Click the Columns tab to see information about the columns, such as their name, type, and length.9.Close the windows and navigate back to the top level of the Explorer window.For information about other operating environments, see Using the Explorer Window in Appendix C or D.Defining SAS Libraries Using the New Library Window66This demonstration shows you how to define a permanent SAS library using the New Library window. If you don’t work in the Windows operating environment, you can skip this demonstration.1.Activate the Explorer window, and then click the New tool.2.In the new window, click Library, and then OK.3.Enter the libref Mydocs.4.Select Enable at Startup.5.Enter the path C:\Documents and Settings.6.Click OK.Double-click the Libraries icon and notice that Mydocs has been defined.Defining SAS Libraries Using the LIBNAME Statement87This demonstration shows you how to define a permanent SAS library by submitting a LIBNAME statement.1. In the Editor window, type the following code:libname sasintro “C:\Documents and Settings”;2. Click the Submit tool.3. Check the log. Notice that the libref was successfully assigned.Creating a Permanent SAS Data Set127This demonstration shows you how to create a permanent SAS data set.Start with the LIBNAME statement from the previous demo in the Editor window, along with additional DATA step code:data revenuedata;infile 'revenue.dat';input Flight $ 1 - 3Category $ 6 - 8PassengerRevenue 12 - 18CargoRevenue 22 - 27;run;1.Change the DATA statement to make the data set name a two-level name that includes SASIntro.2.Highlight the code and click the Submit tool.Check the log. Notice that the new permanent data set has been created.Importing Microsoft Excel Data Using the Import Wizard14This demonstration shows you how to import Microsoft Excel data using the SAS Import Wizard.Put DFWLAX.xls in your My Documents\My SAS Files\SASIntro\PracticeFiles folder.1.Suppose we have a Microsoft Excel spreadsheet of flight data that we want to be able to process inSAS. We want to import that data from Microsoft Excel into a SAS data set, so we’ll use the SAS Import Wizard. The name of the Excel file is DFWLAX.xls. We want to create a temporary SAS data set named DFWLAX in the Work library.2.In SAS, select File Ö Import Data. Make sure Standard data source is selected, and that MicrosoftExcel 97, 2000, or 2002 Workbook is selected.3.Click Next.4.Click Browse to locate DFWLAX.xls.5.Click Open and then OK.6.DFWLAX.xls is listed as the table to import. Click Next.7.Leave Work as the library and type DFWLAX as the member name. Click Next.8.Browse to the location where you want to save the SAS code. Save the code as import.sas in MyDocuments\My SAS Files\SASIntro\PracticeFiles. Make sure that Replace file, if exists, is checked and click Finish.9.View the log to check the import process. Notice that Work.DFWLAX was created.Use the Explorer window to open the Work library and the new DFWLAX data set.Specifying Results Formats164This demonstration shows you how to specify listing results, HTML results, or both. Have Survey data set in Work.Make sure only listing output is selected.Make sure Normal style is selected for HTML output.Use this code to create reports:proc print data=survey;title 'The PRINT Procedure';footnote;run;proc freq data=survey;title1;footnote;tables state;run;proc means data=survey mean std;title1;footnote;var years;class profession;run;1.Submit the program.2.Scroll through output in the Output window.3.Select Tools ÖOptions ÖPreferences and click the Results tab.4.Deselect Create listing and select Create HTML.5.Click OK.6.Resubmit the program and view output in the Results Viewer window.7.Clear all content in the Results window.8.Navigate to the Results tab again. Leave Create HTML selected and select Create listing. ClickOK.9.Resubmit the program again.10.Expand the tree in the Results window to show the two types of output for each PROC step. Click each report icon (first listing, and then HTML) for each PROC step to show reports.Lesson 5 Using PROC PRINT to Create List ReportsCreating a List Report Using PROC PRINT73This demonstration shows you how to create a list report using the PROC PRINT step.1. Type this program:proc print data=sasuser.pilotdata;run;2. Submit the program and check the log.3. Examine the new list report in the Output window.Modifying Your List Report Using the VAR Statement102This demonstration shows you how to modify your list report by using the VAR statement in the PROC PRINT step.Start with the list report from the last demo in the Output window.1. Activate the Editor window to show the program from the last demo. Add the following lineof code between the PROC PRINT statement and the RUN statement:var employeeid firstname lastname jobcode;2. Submit the program and check the log.3. Examine the new list report in the Output window.Lesson 6 Using PROC PRINT to Enhance List ReportsLesson 6: Using PROC PRINT to Enhance List ReportsSorting a SAS Data Set Using PROC SORT116This demonstration shows you how to sequence a SAS data set using PROC SORT. Start with this code in the Editor window:proc print data=sasuser.pilotdata;var employeeid firstname lastname jobcode;run;1. Add the following lines of code before the PROC PRINT step:proc sort data=sasuser.pilotdata out=sortedpilotdata; by lastname firstname;run;2. Change the PROC PRINT statement to this:proc print data=sortedpilotdata;3. Submit the program and check the log.4. Examine the new list report in the Output window.Enhancing Your List Report with Formats and Labels182This demonstration shows you how to enhance a list report by adding formats and labels to PROC PRINT code.Start with the code from the previous demo.1. Change the VAR statement as follows:var employeeid firstname lastname salary;2. Add a LABEL statement to label EmployeeID as ID Number, FirstName as First Name, LastName as Last Name, and Salary as Salary.label EmployeeID='ID Number'FirstName='First Name'LastName='Last Name'Salary=’Salary';3. Add the SPLIT= option to the PROC PRINT statement:proc print data=sortedpilotdata split=' ';4. Add a FORMAT statement to format the Salary variable to represent dollar amounts.format salary dollar8.;5. Submit the program and check the log.6. Examine the new list report in the Output window. Notice the column labels and howthose labels are split. Notice the Salary column.Lesson 7 Using the DATA Step to Read Raw DataLocating and Viewing a Raw Data File75This demonstration shows you how to locate and view the raw data file you’ll read.Start with SAS session where SASIntro has already been defined as C:\Documents and Settings. Have Windows Explorer open to MyDocuments\My SAS Files\SASIntro\PracticeFiles and have pilot.dat in this folder.1.Open the SASIntro library. Remember that you want to name your data set Pilotdata and store it inthe SASIntro library.2.Navigate to the raw data file pilot.dat.3.Open the raw data file.Examine the raw data. If you try to figure out the data in this file, you can see some first names and last names. You might also be able to figure out the job codes. But beyond that, based only on what you see, you would have to guess. That’s why the person that created the raw data file needs to give you more information about the layout, including the field names and locations.Submitting a DATA Step to Read Raw Data19This demonstration shows you how to submit a DATA step and examine your results.Start with this DATA step in the Editor window:data sasintro.pilotdata;infile 'pilot.dat';input EmployeeID $ 1 - 6FirstName $ 7 - 19LastName $ 20 - 34JobCode $ 35 - 41Salary 42 - 47Category $ 48 - 50;run;1.Submit the DATA step.2.Check the SAS log. You see the code that you submitted, and then a reference to the raw data file andits file characteristics. Then you see that the new data set was created.3.Navigate to the SASIntro library and open it. Scroll to find the Pilotdata data set.Open the data set to verify that the data was read correctly.Lesson 8 Using Assignment Statements to Create VariablesLesson 8: Using Assignment Statements to Create VariablesCreating a New Variable Using an Assignment Statement23This demonstration shows you how to create a new variable using an assignment statement. Start with this DATA step in the Editor window:data sasintro.pilotdata;infile 'pilot.dat';input EmployeeID $ 1 – 6FirstName $ 7 – 19LastName $ 20 – 34JobCode $ 35 – 41Salary 42 – 47Category $ 48 - 50;run;1.Add the following assignment statement after the INPUT statement:Bonus=salary*0.10;2. Submit the revised DATA step and check the log.3. Notice that the log shows that the DATA step ran successfully and created the dataset Pilotdata. Notice the number of observations in the data set.4. Add a PROC PRINT step:proc print data=sasintro.pilotdata;run;5. Submit the step and view the report.。