Example: stock market

The Little SAS

The correct bibliographic citation for this manual is as follows: Delwiche, Lora D., and Susan J. Slaughter. 2019. The Little SAS Book: A Primer, Sixth Edition. Cary, NC: SAS Institute Inc. The Little SAS Book: A Primer, Sixth Edition Copyright 2019, SAS Institute Inc., Cary, NC, USA ISBN 978-1-64295-616-0 (Hardcover) ISBN 978-1-64295-283-4 (Paperback) ISBN 978-1-64295-342-8 (Web PDF) ISBN 978-1-64295-343-5 (EPUB) ISBN 978-1-64295-344-2 (Kindle) All rights reserved. Produced in the United States of America. For a hard-copy book: 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. For a Web download or e-book: Your use of this publication shall be governed by the terms established by the vendor at the time you acquire this publication.

6.13 Changing Observations to Variables Using PROC TRANSPOSE 196 6.14 Using SAS Automatic Variables 198 Chapter 7 Writing Flexible Code with the SAS Macro Facility 201 7.1 Macro Concepts 202 7.2 Substituting Text with Macro Variables 204 7.3 Concatenating Macro ...

Tags:

  Corps, Little, Transpose, Proc transpose, The little sas

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of The Little SAS

1 The correct bibliographic citation for this manual is as follows: Delwiche, Lora D., and Susan J. Slaughter. 2019. The Little SAS Book: A Primer, Sixth Edition. Cary, NC: SAS Institute Inc. The Little SAS Book: A Primer, Sixth Edition Copyright 2019, SAS Institute Inc., Cary, NC, USA ISBN 978-1-64295-616-0 (Hardcover) ISBN 978-1-64295-283-4 (Paperback) ISBN 978-1-64295-342-8 (Web PDF) ISBN 978-1-64295-343-5 (EPUB) ISBN 978-1-64295-344-2 (Kindle) All rights reserved. Produced in the United States of America. For a hard-copy book: 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. For a Web download or e-book: Your use of this publication shall be governed by the terms established by the vendor at the time you acquire this publication.

2 The scanning, uploading, and distribution of this book via the Internet or any other means without the permission of the publisher is illegal and punishable by law. Please purchase only authorized electronic editions and do not participate in or encourage electronic piracy of copyrighted materials. Your support of others rights is appreciated. Government Restricted Rights Notice: Use, duplication, or disclosure of this software and related documentation by the government is subject to the Agreement with SAS Institute and the restrictions set forth in FAR , Commercial Computer Software-Restricted Rights (June 1987). SAS Institute Inc., SAS Campus Drive, Cary, North Carolina 27513-2414 October 2019 SAS Institute Inc. provides a complete selection of books and electronic products to help customers use SAS software to its fullest potential. For more information about our e-books, e-learning products, CDs, and hard-copy books, visit the SAS Books Web site at or call 1-800-727-3228.

3 SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. indicates USA registration. Other brand and product names are registered trademarks or trademarks of their respective companies. Contents Acknowledgments ix Introducing SAS Software x About This Book xi About These Authors xv Chapter 1 Getting Started Using SAS Software 1 The SAS Language 2 SAS Data Sets 4 DATA and PROC Steps 6 The DATA Step s Built-in Loop 8 Choosing a Method for Running SAS 10 Reading the SAS Log 12 Using SAS System Options 14 Chapter 2 Accessing Your Data 17 Methods for Getting Your Data into SAS 18 SAS Data Libraries and Data Sets 20 Listing the Contents of a SAS Data Set 22 Reading Excel Files with the IMPORT Procedure 24 Accessing Excel Files Using the XLSX LIBNAME Engine 26 Reading Delimited Files with the IMPORT Procedure 28 Telling SAS Where to Find Your Raw Data 30 Reading Raw Data Separated by Spaces 32 Reading Raw Data Arranged

4 In Columns 34 Reading Raw Data Not in Standard Format 36 Selected Informats 38 Mixing Input Styles 40 Reading Messy Raw Data 42 Reading Multiple Lines of Raw Data per Observation 44 iv Contents Reading Multiple Observations per Line of Raw Data 46 Reading Part of a Raw Data File 48 Controlling Input with Options in the INFILE Statement 50 Reading Delimited Files with the DATA Step 52 Chapter 3 Working with Your Data 55 Using the DATA Step to Modify Data 56 Creating and Modifying Variables 58 Using SAS Functions 60 Selected SAS Character Functions 62 Selected SAS Numeric Functions 64 Using IF-THEN and DO Statements 66 Grouping Observations with IF-THEN/ELSE Statements 68 Subsetting Your Data in a DATA Step 70 Subsetting Your Data Using PROC SQL 72 Writing Multiple Data Sets Using OUTPUT Statements 74 Making Several Observations from One Using OUTPUT Statements 76 Using Iterative DO, DO WHILE, and DO UNTIL Statements 78 Working with SAS Dates 80 Selected Date Informats, Functions, and Formats 82 Using RETAIN and Sum Statements 84 Simplifying Programs with Arrays 86 Using Shortcuts for Lists of Variable Names 88 Using Variable Names with Special Characters 90 Chapter 4 Sorting, Printing.

5 And Summarizing Your Data 93 Using SAS Procedures 94 Subsetting in Procedures with the WHERE Statement 96 Sorting Your Data with PROC SORT 98 Changing the Sort Order for Character Data 100 Printing Your Data with PROC PRINT 102 Changing the Appearance of DataValues with Formats 104 Selected Standard Formats 106 Creating Your Own Formats with PROC FORMAT 108 Contents v Writing a Report to a Text File 110 Summarizing Your Data Using PROC MEANS 112 Writing Summary Statistics to a SAS Data Set 114 Producing One-Way Frequencies with PROC FREQ 116 Producing Crosstabulations with PROC FREQ 118 Grouping Data with User-Defined Formats 120 Producing Tabular Reports with PROC TABULATE 122 Adding Statistics to PROC TABULATE Output 124 Enhancing the Appearance of PROC TABULATE Output 126 Changing Headers in PROC TABULATE Output 128 Producing Simple Output with PROC REPORT 130 Using DEFINE Statements in PROC REPORT 132 Creating Summary Reports with PROC REPORT 134 Adding Summary Breaks to PROC REPORT Output 136 Adding Statistics to PROC REPORT Output 138 Adding Computed Variables to PROC REPORT Output 140 Chapter 5 Enhancing Your Output with ODS 143 Concepts of the Output Delivery System 144 Creating HTML Output 146 Creating RTF Output 148 Creating PDF Output 150 Creating Text Output 152 Customizing Titles and Footnotes 154 Customizing PROC PRINT with the STYLE= Option 156 Customizing PROC REPORT with the STYLE= Option 158 Customizing PROC TABULATE with the STYLE= Option 160 Adding Trafficlighting to Your Output 162 Selected Style Attributes 164 Tracing and Selecting

6 Procedure Output 166 Creating SAS Data Sets from Procedure Output 168 vi Contents Chapter 6 Modifying and Combining SAS Data Sets 171 Stacking Data Sets Using the SET Statement 172 Interleaving Data Sets Using the SET Statement 174 Combining Data Sets Using a One-to-One Match Merge 176 Combining Data Sets Using a One-to-Many Match Merge 178 Using PROC SQL to Join Data Sets 180 Merging Summary Statistics with the Original Data 182 Combining a Grand Total with the Original Data 184 Adding Summary Statistics to Data Using PROC SQL 186 Updating a Master Data Set with Transactions 188 Using SAS Data Set Options 190 Tracking and Selecting Observations with the IN= Option 192 Selecting Observations with the WHERE= Option 194 Changing Observations to Variables Using proc transpose 196 Using SAS Automatic Variables 198 Chapter 7 Writing Flexible Code with the SAS Macro Facility 201 Macro Concepts 202 Substituting Text with Macro Variables 204 Concatenating Macro Variables with Other Text 206 Creating Modular Code with Macros 208 Adding Parameters to Macros 210 Writing Macros with Conditional Logic 212 Using %DO Loops in Macros 214 Writing Data-Driven Programs with CALL SYMPUTX 216 Writing Data-Driven Programs with PROC SQL 218 Debugging Macro Errors 220 Chapter 8 Visualizing Your Data 223 Concepts of ODS Graphics 224 Creating Bar Charts with PROC SGPLOT 226 Creating Histograms and Density Curves with PROC SGPLOT 228 Creating Box Plots with PROC SGPLOT 230 Creating Scatter Plots with PROC SGPLOT 232 Contents vii Creating Series Plots with PROC SGPLOT 234

7 Creating Fitted Curves with PROC SGPLOT 236 Controlling Axes and Reference Lines in PROC SGPLOT 238 Controlling Legends and Insets in PROC SGPLOT 240 Customizing Graph Attributes in PROC SGPLOT 242 Creating Paneled Graphs with PROC SGPANEL 244 Specifying Image Properties and Saving Graphics Output 246 Chapter 9 Using Basic Statistical Procedures 249 Examining the Distribution of Data with PROC UNIVARIATE 250 Creating Statistical Graphics with PROC UNIVARIATE 252 Producing Statistics with PROC MEANS 254 Testing Means with PROC TTEST 256 Creating Statistical Graphics with PROC TTEST 258 Testing Categorical Data with PROC FREQ 260 Creating Statistical Graphics with PROC FREQ 262 Examining Correlations with PROC CORR 264 Creating Statistical Graphics with PROC CORR 266 Using PROC REG for Simple Regression Analysis 268 Creating Statistical Graphics with PROC REG 270 Using PROC ANOVA for One-Way Analysis of Variance 272 Reading the Output of PROC ANOVA 274 Chapter 10 Exporting Your Data 277 Methods for Exporting Your Data 278 Writing Delimited Files with the EXPORT Procedure 280 Writing Delimited Files Using ODS 282 Writing Microsoft Excel Files with the EXPORT Procedure 284 Writing Microsoft Excel Files Using ODS 286 Writing Raw Data Files with the DATA Step 288 viii Contents Chapter 11 Debugging Your SAS Programs 291 Writing SAS Programs That Work 292 Fixing Programs That Don t Work 294 Searching for the Missing Semicolon 296 Note: INPUT Statement Reached Past the End of a Line 298 Note: Lost Card 300 Note: Invalid Data 302 Note.

8 Missing Values Were Generated 304 Note: Numeric Values Have Been Converted to Character (or Vice Versa) 306 DATA Step Produces Wrong Results but No Error Message 308 Error: Invalid Option, Error: The Option Is Not Recognized, or Error: Statement Is Not Valid 310 Note: Variable Is Uninitialized or Error: Variable Not Found 312 SAS Truncates a Character Variable 314 Saving Memory or Disk Space 316 Index 319 Introducing SAS Software SAS software is used by millions of people all over the world in over 147 countries, at over 83,000 sites. SAS (pronounced sass) is both a company and software. When people say SAS, they sometimes mean the software running on their computers and sometimes mean the company, SAS Institute. People often ask what SAS stands for. Originally the letters S-A-S stood for Statistical Analysis System (not to be confused with Scandinavian Airlines System, San Antonio Shoemakers, or the Society for Applied Spectroscopy).

9 But SAS products quickly became so diverse that SAS officially dropped the name Statistical Analysis System and became simply SAS. SAS products The roots of SAS software reach back to the 1970s when it started out as a software package for statistical analysis, but SAS didn t stop there. By the mid-1980s SAS had already branched out into graphics, online data entry, and compilers for the C programming language. In the 1990s, the SAS family tree grew to include tools for visualizing data, administering data warehouses, and building interfaces to the World Wide Web. In the new century, SAS has continued to grow with products designed for cleansing messy data, discovering and developing drugs, detecting money laundering, and building systems for artificial intelligence and machine learning. While SAS has a diverse family of products, most of these products are integrated. That is, they can be put together like building blocks to construct a seamless system.

10 For example, you might use SAS/ACCESS software to read data stored in an external database such as Oracle, analyze it using SAS/ETS software (econometrics and time series software for modeling and forecasting), use ODS Graphics to produce sophisticated plots, and then forward the results in an email message to your colleagues, all in a single computer program. To find out more about the products that are available from SAS, visit the website: Learning SAS In addition to this and other books, there are online resources for learning SAS. SAS Institute has many how-to tutorials and complete courses covering a broad range of topics. Some of these are free, while others are available for a fee. If you don t have access to SAS software at your workplace or school, then there are other ways you can practice what you learn. SAS University Edition is available for free download and installation on your personal computer. Or, you can set up an account to use SAS OnDemand for Academics which runs on servers hosted by SAS Institute.


Related search queries