├── LICENSE ├── README.md ├── code ├── SP4R00d00.sas ├── SP4R01d01.sas ├── SP4R01d02.sas ├── SP4R01d03.sas ├── SP4R02d01.sas ├── SP4R02d02.sas ├── SP4R02d03.sas ├── SP4R02e01.sas ├── SP4R02e02.sas ├── SP4R02e05.sas ├── SP4R02s01.sas ├── SP4R02s02.sas ├── SP4R02s03.sas ├── SP4R02s04.sas ├── SP4R02s05.sas ├── SP4R03s01.sas ├── SP4R03s02.sas ├── SP4R03s03.sas ├── SP4R03s04.sas ├── SP4R03s05.sas ├── SP4R04d01.sas ├── SP4R04d02.sas ├── SP4R04d03.sas ├── SP4R04d04.sas ├── SP4R04e02.sas ├── SP4R04s01.sas ├── SP4R04s02.sas ├── SP4R04s03.sas ├── SP4R04s04.sas ├── SP4R04s05.sas ├── SP4R04s06.sas ├── SP4R04s07.sas ├── SP4R05d01.sas ├── SP4R05d02.sas ├── SP4R05d03.sas ├── SP4R05d04.sas ├── SP4R05d05.sas ├── SP4R05d06.sas ├── SP4R05e03.sas ├── SP4R05e04.sas ├── SP4R05s01.sas ├── SP4R05s02.sas ├── SP4R05s03.sas ├── SP4R05s04.sas ├── SP4R05s05.sas ├── SP4R06d01.sas ├── SP4R06d02.sas ├── SP4R06d03.sas ├── SP4R06d04.sas ├── SP4R06d05.sas ├── SP4R06d06.sas ├── SP4R06d07.sas ├── SP4R06d08.sas ├── SP4R06d09.sas ├── SP4R06s01.sas ├── SP4R06s02.sas ├── SP4R06s03.sas ├── SP4R06s04.sas ├── SP4R06s05.sas ├── SP4R06s06.sas ├── SP4R06s07.sas ├── SP4R06s08.sas ├── SP4R06s09.sas ├── SP4R06s10.sas ├── SP4R07d01.sas ├── SP4R07d02.sas ├── SP4R07d03.sas ├── SP4R07d04.sas ├── SP4R07d05.sas ├── SP4R07d06.sas ├── SP4R07d07.sas ├── SP4R07d08.sas ├── SP4R07d09.sas ├── SP4R07s01.sas ├── SP4R07s02.sas ├── SP4R07s03.sas ├── SP4R07s04.sas ├── SP4R07s05.sas ├── SP4R07s06.sas ├── SP4R07s07.sas ├── SP4R07s08.sas ├── SP4R08d01.sas └── SP4R08s01.sas ├── data ├── allnames.csv ├── amesbyyear.xlsx ├── baseball.csv ├── sales_2000.csv ├── sales_2001.csv ├── sales_2002.csv ├── sales_2003.csv ├── sales_2004.csv ├── sales_2005.csv ├── sales_2006.csv ├── sales_2007.csv ├── sales_2008.csv ├── sales_2009.csv ├── state_pop.txt └── state_pop.xlsx └── notes └── LWSP4R_001.pdf /LICENSE: -------------------------------------------------------------------------------- 1 | Attribution 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More_considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution 4.0 International Public License 58 | 59 | By exercising the Licensed Rights (defined below), You accept and agree 60 | to be bound by the terms and conditions of this Creative Commons 61 | Attribution 4.0 International Public License ("Public License"). To the 62 | extent this Public License may be interpreted as a contract, You are 63 | granted the Licensed Rights in consideration of Your acceptance of 64 | these terms and conditions, and the Licensor grants You such rights in 65 | consideration of benefits the Licensor receives from making the 66 | Licensed Material available under these terms and conditions. 67 | 68 | 69 | Section 1 -- Definitions. 70 | 71 | a. Adapted Material means material subject to Copyright and Similar 72 | Rights that is derived from or based upon the Licensed Material 73 | and in which the Licensed Material is translated, altered, 74 | arranged, transformed, or otherwise modified in a manner requiring 75 | permission under the Copyright and Similar Rights held by the 76 | Licensor. For purposes of this Public License, where the Licensed 77 | Material is a musical work, performance, or sound recording, 78 | Adapted Material is always produced where the Licensed Material is 79 | synched in timed relation with a moving image. 80 | 81 | b. Adapter's License means the license You apply to Your Copyright 82 | and Similar Rights in Your contributions to Adapted Material in 83 | accordance with the terms and conditions of this Public License. 84 | 85 | c. Copyright and Similar Rights means copyright and/or similar rights 86 | closely related to copyright including, without limitation, 87 | performance, broadcast, sound recording, and Sui Generis Database 88 | Rights, without regard to how the rights are labeled or 89 | categorized. For purposes of this Public License, the rights 90 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 91 | Rights. 92 | 93 | d. Effective Technological Measures means those measures that, in the 94 | absence of proper authority, may not be circumvented under laws 95 | fulfilling obligations under Article 11 of the WIPO Copyright 96 | Treaty adopted on December 20, 1996, and/or similar international 97 | agreements. 98 | 99 | e. Exceptions and Limitations means fair use, fair dealing, and/or 100 | any other exception or limitation to Copyright and Similar Rights 101 | that applies to Your use of the Licensed Material. 102 | 103 | f. Licensed Material means the artistic or literary work, database, 104 | or other material to which the Licensor applied this Public 105 | License. 106 | 107 | g. Licensed Rights means the rights granted to You subject to the 108 | terms and conditions of this Public License, which are limited to 109 | all Copyright and Similar Rights that apply to Your use of the 110 | Licensed Material and that the Licensor has authority to license. 111 | 112 | h. Licensor means the individual(s) or entity(ies) granting rights 113 | under this Public License. 114 | 115 | i. Share means to provide material to the public by any means or 116 | process that requires permission under the Licensed Rights, such 117 | as reproduction, public display, public performance, distribution, 118 | dissemination, communication, or importation, and to make material 119 | available to the public including in ways that members of the 120 | public may access the material from a place and at a time 121 | individually chosen by them. 122 | 123 | j. Sui Generis Database Rights means rights other than copyright 124 | resulting from Directive 96/9/EC of the European Parliament and of 125 | the Council of 11 March 1996 on the legal protection of databases, 126 | as amended and/or succeeded, as well as other essentially 127 | equivalent rights anywhere in the world. 128 | 129 | k. You means the individual or entity exercising the Licensed Rights 130 | under this Public License. Your has a corresponding meaning. 131 | 132 | 133 | Section 2 -- Scope. 134 | 135 | a. License grant. 136 | 137 | 1. Subject to the terms and conditions of this Public License, 138 | the Licensor hereby grants You a worldwide, royalty-free, 139 | non-sublicensable, non-exclusive, irrevocable license to 140 | exercise the Licensed Rights in the Licensed Material to: 141 | 142 | a. reproduce and Share the Licensed Material, in whole or 143 | in part; and 144 | 145 | b. produce, reproduce, and Share Adapted Material. 146 | 147 | 2. Exceptions and Limitations. For the avoidance of doubt, where 148 | Exceptions and Limitations apply to Your use, this Public 149 | License does not apply, and You do not need to comply with 150 | its terms and conditions. 151 | 152 | 3. Term. The term of this Public License is specified in Section 153 | 6(a). 154 | 155 | 4. Media and formats; technical modifications allowed. The 156 | Licensor authorizes You to exercise the Licensed Rights in 157 | all media and formats whether now known or hereafter created, 158 | and to make technical modifications necessary to do so. The 159 | Licensor waives and/or agrees not to assert any right or 160 | authority to forbid You from making technical modifications 161 | necessary to exercise the Licensed Rights, including 162 | technical modifications necessary to circumvent Effective 163 | Technological Measures. For purposes of this Public License, 164 | simply making modifications authorized by this Section 2(a) 165 | (4) never produces Adapted Material. 166 | 167 | 5. Downstream recipients. 168 | 169 | a. Offer from the Licensor -- Licensed Material. Every 170 | recipient of the Licensed Material automatically 171 | receives an offer from the Licensor to exercise the 172 | Licensed Rights under the terms and conditions of this 173 | Public License. 174 | 175 | b. No downstream restrictions. You may not offer or impose 176 | any additional or different terms or conditions on, or 177 | apply any Effective Technological Measures to, the 178 | Licensed Material if doing so restricts exercise of the 179 | Licensed Rights by any recipient of the Licensed 180 | Material. 181 | 182 | 6. No endorsement. Nothing in this Public License constitutes or 183 | may be construed as permission to assert or imply that You 184 | are, or that Your use of the Licensed Material is, connected 185 | with, or sponsored, endorsed, or granted official status by, 186 | the Licensor or others designated to receive attribution as 187 | provided in Section 3(a)(1)(A)(i). 188 | 189 | b. Other rights. 190 | 191 | 1. Moral rights, such as the right of integrity, are not 192 | licensed under this Public License, nor are publicity, 193 | privacy, and/or other similar personality rights; however, to 194 | the extent possible, the Licensor waives and/or agrees not to 195 | assert any such rights held by the Licensor to the limited 196 | extent necessary to allow You to exercise the Licensed 197 | Rights, but not otherwise. 198 | 199 | 2. Patent and trademark rights are not licensed under this 200 | Public License. 201 | 202 | 3. To the extent possible, the Licensor waives any right to 203 | collect royalties from You for the exercise of the Licensed 204 | Rights, whether directly or through a collecting society 205 | under any voluntary or waivable statutory or compulsory 206 | licensing scheme. In all other cases the Licensor expressly 207 | reserves any right to collect such royalties. 208 | 209 | 210 | Section 3 -- License Conditions. 211 | 212 | Your exercise of the Licensed Rights is expressly made subject to the 213 | following conditions. 214 | 215 | a. Attribution. 216 | 217 | 1. If You Share the Licensed Material (including in modified 218 | form), You must: 219 | 220 | a. retain the following if it is supplied by the Licensor 221 | with the Licensed Material: 222 | 223 | i. identification of the creator(s) of the Licensed 224 | Material and any others designated to receive 225 | attribution, in any reasonable manner requested by 226 | the Licensor (including by pseudonym if 227 | designated); 228 | 229 | ii. a copyright notice; 230 | 231 | iii. a notice that refers to this Public License; 232 | 233 | iv. a notice that refers to the disclaimer of 234 | warranties; 235 | 236 | v. a URI or hyperlink to the Licensed Material to the 237 | extent reasonably practicable; 238 | 239 | b. indicate if You modified the Licensed Material and 240 | retain an indication of any previous modifications; and 241 | 242 | c. indicate the Licensed Material is licensed under this 243 | Public License, and include the text of, or the URI or 244 | hyperlink to, this Public License. 245 | 246 | 2. You may satisfy the conditions in Section 3(a)(1) in any 247 | reasonable manner based on the medium, means, and context in 248 | which You Share the Licensed Material. For example, it may be 249 | reasonable to satisfy the conditions by providing a URI or 250 | hyperlink to a resource that includes the required 251 | information. 252 | 253 | 3. If requested by the Licensor, You must remove any of the 254 | information required by Section 3(a)(1)(A) to the extent 255 | reasonably practicable. 256 | 257 | 4. If You Share Adapted Material You produce, the Adapter's 258 | License You apply must not prevent recipients of the Adapted 259 | Material from complying with this Public License. 260 | 261 | 262 | Section 4 -- Sui Generis Database Rights. 263 | 264 | Where the Licensed Rights include Sui Generis Database Rights that 265 | apply to Your use of the Licensed Material: 266 | 267 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 268 | to extract, reuse, reproduce, and Share all or a substantial 269 | portion of the contents of the database; 270 | 271 | b. if You include all or a substantial portion of the database 272 | contents in a database in which You have Sui Generis Database 273 | Rights, then the database in which You have Sui Generis Database 274 | Rights (but not its individual contents) is Adapted Material; and 275 | 276 | c. You must comply with the conditions in Section 3(a) if You Share 277 | all or a substantial portion of the contents of the database. 278 | 279 | For the avoidance of doubt, this Section 4 supplements and does not 280 | replace Your obligations under this Public License where the Licensed 281 | Rights include other Copyright and Similar Rights. 282 | 283 | 284 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 285 | 286 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 287 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 288 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 289 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 290 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 291 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 292 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 293 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 294 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 295 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 296 | 297 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 298 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 299 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 300 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 301 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 302 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 303 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 304 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 305 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 306 | 307 | c. The disclaimer of warranties and limitation of liability provided 308 | above shall be interpreted in a manner that, to the extent 309 | possible, most closely approximates an absolute disclaimer and 310 | waiver of all liability. 311 | 312 | 313 | Section 6 -- Term and Termination. 314 | 315 | a. This Public License applies for the term of the Copyright and 316 | Similar Rights licensed here. However, if You fail to comply with 317 | this Public License, then Your rights under this Public License 318 | terminate automatically. 319 | 320 | b. Where Your right to use the Licensed Material has terminated under 321 | Section 6(a), it reinstates: 322 | 323 | 1. automatically as of the date the violation is cured, provided 324 | it is cured within 30 days of Your discovery of the 325 | violation; or 326 | 327 | 2. upon express reinstatement by the Licensor. 328 | 329 | For the avoidance of doubt, this Section 6(b) does not affect any 330 | right the Licensor may have to seek remedies for Your violations 331 | of this Public License. 332 | 333 | c. For the avoidance of doubt, the Licensor may also offer the 334 | Licensed Material under separate terms or conditions or stop 335 | distributing the Licensed Material at any time; however, doing so 336 | will not terminate this Public License. 337 | 338 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 339 | License. 340 | 341 | 342 | Section 7 -- Other Terms and Conditions. 343 | 344 | a. The Licensor shall not be bound by any additional or different 345 | terms or conditions communicated by You unless expressly agreed. 346 | 347 | b. Any arrangements, understandings, or agreements regarding the 348 | Licensed Material not stated herein are separate from and 349 | independent of the terms and conditions of this Public License. 350 | 351 | 352 | Section 8 -- Interpretation. 353 | 354 | a. For the avoidance of doubt, this Public License does not, and 355 | shall not be interpreted to, reduce, limit, restrict, or impose 356 | conditions on any use of the Licensed Material that could lawfully 357 | be made without permission under this Public License. 358 | 359 | b. To the extent possible, if any provision of this Public License is 360 | deemed unenforceable, it shall be automatically reformed to the 361 | minimum extent necessary to make it enforceable. If the provision 362 | cannot be reformed, it shall be severed from this Public License 363 | without affecting the enforceability of the remaining terms and 364 | conditions. 365 | 366 | c. No term or condition of this Public License will be waived and no 367 | failure to comply consented to unless expressly agreed to by the 368 | Licensor. 369 | 370 | d. Nothing in this Public License constitutes or may be interpreted 371 | as a limitation upon, or waiver of, any privileges and immunities 372 | that apply to the Licensor or You, including from the legal 373 | processes of any jurisdiction or authority. 374 | 375 | 376 | ======================================================================= 377 | 378 | Creative Commons is not a party to its public 379 | licenses. Notwithstanding, Creative Commons may elect to apply one of 380 | its public licenses to material it publishes and in those instances 381 | will be considered the “Licensor.” The text of the Creative Commons 382 | public licenses is dedicated to the public domain under the CC0 Public 383 | Domain Dedication. Except for the limited purpose of indicating that 384 | material is shared under a Creative Commons public license or as 385 | otherwise permitted by the Creative Commons policies published at 386 | creativecommons.org/policies, Creative Commons does not authorize the 387 | use of the trademark "Creative Commons" or any other trademark or logo 388 | of Creative Commons without its prior written consent including, 389 | without limitation, in connection with any unauthorized modifications 390 | to any of its public licenses or any other arrangements, 391 | understandings, or agreements concerning use of licensed material. For 392 | the avoidance of doubt, this paragraph does not form part of the 393 | public licenses. 394 | 395 | Creative Commons may be contacted at creativecommons.org. 396 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SAS Programming for R Users (Course Materials) 2 | This project contains the learning materials for the free SAS programming course, _SAS Programming for R Users_. 3 | 4 | SAS Training offers a free e-Learning version of this course, which includes lecture, demos, and exercises. 5 | There are also occasionally instructor-led sessions of this course in the "Live Web" format for no charge; see 6 | [the SAS training web site for the schedule and the Self-paced e-Learning link](https://support.sas.com/edu/schedules.html?id=3033). 7 | 8 | ## Materials Included: 9 | The course materials supplied here contain everything you need for self-paced 10 | learning or (for experts) to teach the course to other students. Materials 11 | include: 12 | 13 | - [PDF version of the course notes](notes/LWSP4R_001.pdf) (over 600 pages) 14 | - Sample data files in CSV, XLSX, text, and SAS code formats 15 | - Over 80 SAS programs for course exercises 16 | 17 | ## About The Course 18 | This course is for experienced R users who want to apply their existing skills and extend them to the SAS environment. 19 | Emphasis will be placed on programming and not statistical theory or interpretation. Students of this course should have knowledge of plotting, manipulating data, iterative processing, creating functions, applying functions, linear models, generalized linear models, mixed models, stepwise model selection, matrix algebra, and statistical simulations. 20 | 21 | Learn how to: 22 | 23 | - read and write SAS programs 24 | - import various forms of data 25 | - subset and merge data tables 26 | - do iterative processing and simulate new data 27 | - create new variables and functions 28 | - create and enhance plots of all types 29 | - apply descriptive and inferential procedures including regression, 30 | logistic regression, analysis of variance, 31 | stepwise model selection, and mixed models 32 | - conduct matrix algebra and statistical simulations in the interactive matrix language (IML) 33 | - call R from SAS to use as a complimentary resource. 34 | 35 | ## Lab Machine Configuration 36 | The Live Web version of this course uses a virtual lab environment. 37 | The lab environment features SAS for Windows, SAS Enterprise Guide, 38 | and SAS Studio. Any of these can be used as the programming environment. 39 | A small part of the course addresses the use of SAS Enterprise Miner. 40 | 41 | Self-paced learners or anyone using this material in a classroom setting can 42 | adapt the course to use their own instance of Base SAS (Display Manager), 43 | SAS Enterprise Guide, or SAS Studio. SAS can run on Windows or any supported 44 | variety of UNIX or Linux. 45 | 46 | The SAS program examples assume a home directory of "`s:\workshop`" for the 47 | SAS programs and data files. To adapt to your own environment, simply 48 | change those path references to a location that works for your own 49 | machine. If using SAS University Edition, you can use the 50 | `/folders/myfolder` [shared folder structure](https://support.sas.com/software/products/university-edition/faq/shared_folder_whatis.htm) 51 | as a "home base" for the code and data. 52 | 53 | ### SAS Products 54 | The following SAS products are used for the bulk of the course: 55 | 56 | - Base SAS 57 | - SAS/STAT 58 | - SAS/IML 59 | 60 | These products are all [included with SAS University Edition](http://www.sas.com/en_us/software/university-edition.html), 61 | a free SAS programming environment that you can download from SAS. 62 | 63 | ### Integration with R 64 | Chapter 8 of this course (chapter title: "A Bridge between SAS and R") 65 | shows examples of integrating R with SAS. 66 | The integration with R requires an installed version of R, 67 | plus a few additional configuration settings within 68 | your SAS environment. These settings are described in Chapter 8 of the course 69 | notes. 70 | 71 | *Note:* Because you cannot modify its configuration, SAS University Edition 72 | does not support integration with R. You will still be able to complete 73 | Chapters 1 through 7 without the R integration. 74 | 75 | # Licensing 76 | You can obtain a copy of the license at [LICENSE.txt](https://github.com/sassoftware/sas-prog-for-r-users/blob/master/LICENSE) 77 | -------------------------------------------------------------------------------- /code/SP4R00d00.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R00d00*/ 7 | 8 | /*This program creates the SP4R library and connects it to the saved data sets.*/ 9 | 10 | /*Change this path to the appropriate location*/ 11 | %let path = s:\workshop; 12 | 13 | /* 14 | This course will use the library name sp4r. 15 | Each data set name will begin with the library name followed by a period. 16 | For example, to save a data set called 'dogs' in the SP4R library 17 | we will use the name sp4r.dogs 18 | */ 19 | libname sp4r "&path"; 20 | 21 | -------------------------------------------------------------------------------- /code/SP4R01d01.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R01d01*/ 7 | 8 | /****************************** 9 | Introduction 10 | ******************************/ 11 | 12 | proc format; 13 | value yesnofmt 14 | 0="No" 15 | 1="Yes"; 16 | value ftvfmt 17 | 0="0" 18 | 1="1" 19 | 2-high="2+"; 20 | value ptlfmt 21 | 0="0" 22 | 1-high="1+"; 23 | run; 24 | 25 | /* 26 | LIST OF VARIABLES: 27 | 28 | Columns Variable Abbreviation 29 | ----------------------------------------------------------------------------- 30 | 2-4 Identification Code ID 31 | 32 | 10 Low Birth Weight (0 = Birth Weight >= 2500g, LOW 33 | 1 = Birth Weight < 2500g) 34 | 35 | 17-18 Age of the Mother in Years AGE 36 | 37 | 23-25 Weight in Pounds at the Last Menstrual Period LWT 38 | 39 | 32 Ethnicity ETH 40 | 41 | 40 Smoking Status During Pregnancy (1 = Yes, 0 = No) SMOKE 42 | 43 | 48 History of Premature Labor (0 = None 1 = One, etc.) PTL 44 | 45 | 55 History of Hypertension (1 = Yes, 0 = No) HT 46 | 47 | 61 Presence of Uterine Irritability (1 = Yes, 0 = No) UI 48 | 49 | 67 Number of Physician Visits During the First Trimester FTV 50 | (0 = None, 1 = One, 2 = Two, etc.) 51 | 52 | 73-76 Birth Weight in Grams BWT 53 | ----------------------------------------------------------------------------- 54 | */ 55 | 56 | data work.birth; 57 | input ID LOW AGE LWT ETH SMOKE PTL HT UI FTV BWT; 58 | if FTV>2 then FTV=2; 59 | if PTL>1 then PTL=1; 60 | label 61 | ID="ID Code" 62 | LOW="Birth Weight < 2500 Grams" 63 | AGE="Mom's Age" 64 | LWT="Mom's Weight Last Menstrual Period" 65 | ETH="Ethnicity" 66 | SMOKE="Smoking Status" 67 | PTL="Hx of Premature Labor" 68 | HT="Hx of Hypertension" 69 | UI="Hx of Uterine Irritability" 70 | FTV="MD Visits 1st Trimester" 71 | BWT="Birth Weight, Grams" 72 | ; 73 | format LOW SMOKE HT UI yesnofmt. PTL ptlfmt. ftv ftvfmt.; 74 | datalines; 75 | 85 0 19 182 2 0 0 0 1 0 2523 76 | 86 0 33 155 3 0 0 0 0 3 2551 77 | 87 0 20 105 1 1 0 0 0 1 2557 78 | 88 0 21 108 1 1 0 0 1 2 2594 79 | 89 0 18 107 1 1 0 0 1 0 2600 80 | 91 0 21 124 3 0 0 0 0 0 2622 81 | 92 0 22 118 1 0 0 0 0 1 2637 82 | 93 0 17 103 3 0 0 0 0 1 2637 83 | 94 0 29 123 1 1 0 0 0 1 2663 84 | 95 0 26 113 1 1 0 0 0 0 2665 85 | 96 0 19 95 3 0 0 0 0 0 2722 86 | 97 0 19 150 3 0 0 0 0 1 2733 87 | 98 0 22 95 3 0 0 1 0 0 2750 88 | 99 0 30 107 3 0 1 0 1 2 2750 89 | 100 0 18 100 1 1 0 0 0 0 2769 90 | 101 0 18 100 1 1 0 0 0 0 2769 91 | 102 0 15 98 2 0 0 0 0 0 2778 92 | 103 0 25 118 1 1 0 0 0 3 2782 93 | 104 0 20 120 3 0 0 0 1 0 2807 94 | 105 0 28 120 1 1 0 0 0 1 2821 95 | 106 0 32 121 3 0 0 0 0 2 2835 96 | 107 0 31 100 1 0 0 0 1 3 2835 97 | 108 0 36 202 1 0 0 0 0 1 2836 98 | 109 0 28 120 3 0 0 0 0 0 2863 99 | 111 0 25 120 3 0 0 0 1 2 2877 100 | 112 0 28 167 1 0 0 0 0 0 2877 101 | 113 0 17 122 1 1 0 0 0 0 2906 102 | 114 0 29 150 1 0 0 0 0 2 2920 103 | 115 0 26 168 2 1 0 0 0 0 2920 104 | 116 0 17 113 2 0 0 0 0 1 2920 105 | 117 0 17 113 2 0 0 0 0 1 2920 106 | 118 0 24 90 1 1 1 0 0 1 2948 107 | 119 0 35 121 2 1 1 0 0 1 2948 108 | 120 0 25 155 1 0 0 0 0 1 2977 109 | 121 0 25 125 2 0 0 0 0 0 2977 110 | 123 0 29 140 1 1 0 0 0 2 2977 111 | 124 0 19 138 1 1 0 0 0 2 2977 112 | 125 0 27 124 1 1 0 0 0 0 2992 113 | 126 0 31 215 1 1 0 0 0 2 3005 114 | 127 0 33 109 1 1 0 0 0 1 3033 115 | 128 0 21 185 2 1 0 0 0 2 3042 116 | 129 0 19 189 1 0 0 0 0 2 3062 117 | 130 0 23 130 2 0 0 0 0 1 3062 118 | 131 0 21 160 1 0 0 0 0 0 3062 119 | 132 0 18 90 1 1 0 0 1 0 3076 120 | 133 0 18 90 1 1 0 0 1 0 3076 121 | 134 0 32 132 1 0 0 0 0 4 3080 122 | 135 0 19 132 3 0 0 0 0 0 3090 123 | 136 0 24 115 1 0 0 0 0 2 3090 124 | 137 0 22 85 3 1 0 0 0 0 3090 125 | 138 0 22 120 1 0 0 1 0 1 3100 126 | 139 0 23 128 3 0 0 0 0 0 3104 127 | 140 0 22 130 1 1 0 0 0 0 3132 128 | 141 0 30 95 1 1 0 0 0 2 3147 129 | 142 0 19 115 3 0 0 0 0 0 3175 130 | 143 0 16 110 3 0 0 0 0 0 3175 131 | 144 0 21 110 3 1 0 0 1 0 3203 132 | 145 0 30 153 3 0 0 0 0 0 3203 133 | 146 0 20 103 3 0 0 0 0 0 3203 134 | 147 0 17 119 3 0 0 0 0 0 3225 135 | 148 0 17 119 3 0 0 0 0 0 3225 136 | 149 0 23 119 3 0 0 0 0 2 3232 137 | 150 0 24 110 3 0 0 0 0 0 3232 138 | 151 0 28 140 1 0 0 0 0 0 3234 139 | 154 0 26 133 3 1 2 0 0 0 3260 140 | 155 0 20 169 3 0 1 0 1 1 3274 141 | 156 0 24 115 3 0 0 0 0 2 3274 142 | 159 0 28 250 3 1 0 0 0 6 3303 143 | 160 0 20 141 1 0 2 0 1 1 3317 144 | 161 0 22 158 2 0 1 0 0 2 3317 145 | 162 0 22 112 1 1 2 0 0 0 3317 146 | 163 0 31 150 3 1 0 0 0 2 3321 147 | 164 0 23 115 3 1 0 0 0 1 3331 148 | 166 0 16 112 2 0 0 0 0 0 3374 149 | 167 0 16 135 1 1 0 0 0 0 3374 150 | 168 0 18 229 2 0 0 0 0 0 3402 151 | 169 0 25 140 1 0 0 0 0 1 3416 152 | 170 0 32 134 1 1 1 0 0 4 3430 153 | 172 0 20 121 2 1 0 0 0 0 3444 154 | 173 0 23 190 1 0 0 0 0 0 3459 155 | 174 0 22 131 1 0 0 0 0 1 3460 156 | 175 0 32 170 1 0 0 0 0 0 3473 157 | 176 0 30 110 3 0 0 0 0 0 3475 158 | 177 0 20 127 3 0 0 0 0 0 3487 159 | 179 0 23 123 3 0 0 0 0 0 3544 160 | 180 0 17 120 3 1 0 0 0 0 3572 161 | 181 0 19 105 3 0 0 0 0 0 3572 162 | 182 0 23 130 1 0 0 0 0 0 3586 163 | 183 0 36 175 1 0 0 0 0 0 3600 164 | 184 0 22 125 1 0 0 0 0 1 3614 165 | 185 0 24 133 1 0 0 0 0 0 3614 166 | 186 0 21 134 3 0 0 0 0 2 3629 167 | 187 0 19 235 1 1 0 1 0 0 3629 168 | 188 0 25 95 1 1 3 0 1 0 3637 169 | 189 0 16 135 1 1 0 0 0 0 3643 170 | 190 0 29 135 1 0 0 0 0 1 3651 171 | 191 0 29 154 1 0 0 0 0 1 3651 172 | 192 0 19 147 1 1 0 0 0 0 3651 173 | 193 0 19 147 1 1 0 0 0 0 3651 174 | 195 0 30 137 1 0 0 0 0 1 3699 175 | 196 0 24 110 1 0 0 0 0 1 3728 176 | 197 0 19 184 1 1 0 1 0 0 3756 177 | 199 0 24 110 3 0 1 0 0 0 3770 178 | 200 0 23 110 1 0 0 0 0 1 3770 179 | 201 0 20 120 3 0 0 0 0 0 3770 180 | 202 0 25 241 2 0 0 1 0 0 3790 181 | 203 0 30 112 1 0 0 0 0 1 3799 182 | 204 0 22 169 1 0 0 0 0 0 3827 183 | 205 0 18 120 1 1 0 0 0 2 3856 184 | 206 0 16 170 2 0 0 0 0 4 3860 185 | 207 0 32 186 1 0 0 0 0 2 3860 186 | 208 0 18 120 3 0 0 0 0 1 3884 187 | 209 0 29 130 1 1 0 0 0 2 3884 188 | 210 0 33 117 1 0 0 0 1 1 3912 189 | 211 0 20 170 1 1 0 0 0 0 3940 190 | 212 0 28 134 3 0 0 0 0 1 3941 191 | 213 0 14 135 1 0 0 0 0 0 3941 192 | 214 0 28 130 3 0 0 0 0 0 3969 193 | 215 0 25 120 1 0 0 0 0 2 3983 194 | 216 0 16 95 3 0 0 0 0 1 3997 195 | 217 0 20 158 1 0 0 0 0 1 3997 196 | 218 0 26 160 3 0 0 0 0 0 4054 197 | 219 0 21 115 1 0 0 0 0 1 4054 198 | 220 0 22 129 1 0 0 0 0 0 4111 199 | 221 0 25 130 1 0 0 0 0 2 4153 200 | 222 0 31 120 1 0 0 0 0 2 4167 201 | 223 0 35 170 1 0 1 0 0 1 4174 202 | 224 0 19 120 1 1 0 0 0 0 4238 203 | 225 0 24 116 1 0 0 0 0 1 4593 204 | 226 0 45 123 1 0 0 0 0 1 4990 205 | 4 1 28 120 3 1 1 0 1 0 709 206 | 10 1 29 130 1 0 0 0 1 2 1021 207 | 11 1 34 187 2 1 0 1 0 0 1135 208 | 13 1 25 105 3 0 1 1 0 0 1330 209 | 15 1 25 85 3 0 0 0 1 0 1474 210 | 16 1 27 150 3 0 0 0 0 0 1588 211 | 17 1 23 97 3 0 0 0 1 1 1588 212 | 18 1 24 128 2 0 1 0 0 1 1701 213 | 19 1 24 132 3 0 0 1 0 0 1729 214 | 20 1 21 165 1 1 0 1 0 1 1790 215 | 22 1 32 105 1 1 0 0 0 0 1818 216 | 23 1 19 91 1 1 2 0 1 0 1885 217 | 24 1 25 115 3 0 0 0 0 0 1893 218 | 25 1 16 130 3 0 0 0 0 1 1899 219 | 26 1 25 92 1 1 0 0 0 0 1928 220 | 27 1 20 150 1 1 0 0 0 2 1928 221 | 28 1 21 200 2 0 0 0 1 2 1928 222 | 29 1 24 155 1 1 1 0 0 0 1936 223 | 30 1 21 103 3 0 0 0 0 0 1970 224 | 31 1 20 125 3 0 0 0 1 0 2055 225 | 32 1 25 89 3 0 2 0 0 1 2055 226 | 33 1 19 102 1 0 0 0 0 2 2082 227 | 34 1 19 112 1 1 0 0 1 0 2084 228 | 35 1 26 117 1 1 1 0 0 0 2084 229 | 36 1 24 138 1 0 0 0 0 0 2100 230 | 37 1 17 130 3 1 1 0 1 0 2125 231 | 40 1 20 120 2 1 0 0 0 3 2126 232 | 42 1 22 130 1 1 1 0 1 1 2187 233 | 43 1 27 130 2 0 0 0 1 0 2187 234 | 44 1 20 80 3 1 0 0 1 0 2211 235 | 45 1 17 110 1 1 0 0 0 0 2225 236 | 46 1 25 105 3 0 1 0 0 1 2240 237 | 47 1 20 109 3 0 0 0 0 0 2240 238 | 49 1 18 148 3 0 0 0 0 0 2282 239 | 50 1 18 110 2 1 1 0 0 0 2296 240 | 51 1 20 121 1 1 1 0 1 0 2296 241 | 52 1 21 100 3 0 1 0 0 4 2301 242 | 54 1 26 96 3 0 0 0 0 0 2325 243 | 56 1 31 102 1 1 1 0 0 1 2353 244 | 57 1 15 110 1 0 0 0 0 0 2353 245 | 59 1 23 187 2 1 0 0 0 1 2367 246 | 60 1 20 122 2 1 0 0 0 0 2381 247 | 61 1 24 105 2 1 0 0 0 0 2381 248 | 62 1 15 115 3 0 0 0 1 0 2381 249 | 63 1 23 120 3 0 0 0 0 0 2395 250 | 65 1 30 142 1 1 1 0 0 0 2410 251 | 67 1 22 130 1 1 0 0 0 1 2410 252 | 68 1 17 120 1 1 0 0 0 3 2414 253 | 69 1 23 110 1 1 1 0 0 0 2424 254 | 71 1 17 120 2 0 0 0 0 2 2438 255 | 75 1 26 154 3 0 1 1 0 1 2442 256 | 76 1 20 105 3 0 0 0 0 3 2450 257 | 77 1 26 190 1 1 0 0 0 0 2466 258 | 78 1 14 101 3 1 1 0 0 0 2466 259 | 79 1 28 95 1 1 0 0 0 2 2466 260 | 81 1 14 100 3 0 0 0 0 2 2495 261 | 82 1 23 94 3 1 0 0 0 0 2495 262 | 83 1 17 142 2 0 0 1 0 0 2495 263 | 84 1 21 130 1 1 0 1 0 3 2495 264 | ; 265 | run; 266 | 267 | ods listing; 268 | ods select basicmeasures histogram qqplot; 269 | proc univariate data=work.birth; 270 | var bwt; 271 | histogram bwt / normal(mu=est sigma=est); 272 | qqplot bwt / normal(mu=est sigma=est); 273 | run; 274 | 275 | proc freq data=work.birth; 276 | table low smoke ht ptl; 277 | run; 278 | 279 | ods select nobs parameters postsummaries postintervals autocorr tadpanel; 280 | proc mcmc data=work.birth outpost=birthout diag=all dic propcov=quanew 281 | nbi=5000 ntu=5000 nmc=200000 thin=10 mchistory=brief plots(smooth)=all seed=27513 stats=all; 282 | parms (beta0 beta1 beta2 beta3 beta4) 0; 283 | prior beta: ~ normal(0, var=100); 284 | p=logistic(beta0+beta1*smoke+beta2*ht+ beta3*lwt+beta4*ptl); 285 | model low ~ binary(p); 286 | title "Bayesian Analysis of Low Birth Weight Data"; 287 | run; 288 | title; 289 | 290 | /***************************************************************************************************/ 291 | /*Poker Hands*/ 292 | proc iml; 293 | 294 | *Specify number of hands; 295 | nHands=10; 296 | 297 | *Create deck; 298 | rank={A,2,3,4,5,6,7,8,9,10,J,Q,K}; 299 | suit={C D H S}; 300 | 301 | *Clubs diamonds hearts spades; 302 | deck=concat(right(repeat(rank,1,4)),repeat(suit,13,1)); 303 | print deck; 304 | 305 | *Sample cards from deck; 306 | cards=sample(deck,(23//nhands),"WOR"); 307 | 308 | *Combine 1st and 2nd card for each person into single cell; 309 | card1=cards[,1:9]; 310 | card2=cards[,10:18]; 311 | community=cards[,19:23]; 312 | hands=concat(card1,",",card2) || community; 313 | 314 | *Create column names; 315 | do i=1 to 9; 316 | name=name || ("p"+strip(char(i))); 317 | end; 318 | 319 | name=name || {c1 c2 c3 c4 c5}; 320 | print (hands[1:10,]) [colname=name]; 321 | 322 | *Probability of pocket aces?; 323 | deck = repeat(rank,4); 324 | hands=10000; 325 | call randseed(802); 326 | 327 | *Sample many hands and count the number of pocet aces; 328 | count = 0; 329 | do i=1 to hands; 330 | sam = sample(deck,2,"WOR"); 331 | aces= (sam[1]='A' & sam[2]='A'); 332 | if aces=1 then do; 333 | count=count+1; 334 | end; 335 | end; 336 | 337 | *Print results; 338 | p=count/hands; 339 | print count hands p; 340 | quit; 341 | 342 | /***************************************************************************************************/ 343 | /*Sampling continuos data*/ 344 | proc iml; 345 | nRep=1000; 346 | call randseed(112358); 347 | 348 | n=30; 349 | mean={20, 5, 10}; 350 | corr={1 .2 .2, .2 1 .2, .2 .2 1}; 351 | var={5, 3, 7}; 352 | beta={ 1, 2, .5}; 353 | resvar=14; 354 | 355 | sddiag=diag(sqrt(var)); 356 | cov=sddiag * corr * sddiag; 357 | 358 | x=randNormal(n*nRep,mean,cov); 359 | 360 | yPred=x * beta; 361 | error=randfun(n*nrep,"Normal",0,sqrt(resvar)); 362 | y=yPred + error; 363 | 364 | temp=repeat((1:nrep)`,1,n); 365 | iteration=colvec(temp); 366 | 367 | sampleData=iteration || x || y; 368 | create temp from sampleData [colname={iteration x c1 c2 y}]; 369 | append from sampleData; 370 | close temp; 371 | store; 372 | quit; 373 | 374 | proc glm data=temp noprint outstat=regResults; 375 | by iteration; 376 | model y=x c1 c2; 377 | run;quit; 378 | 379 | proc iml; 380 | use regResults; 381 | read all var {prob} where(_SOURCE_='X' & _TYPE_='SS3') into prob; 382 | close regResults; 383 | 384 | significant=prob < .05; power=significant[:,]; 385 | print power; 386 | quit; 387 | 388 | /***************************************************************************************************/ 389 | /*Call R from SAS/IML*/ 390 | proc iml; 391 | call ExportDataSetToR("work.birth","birth"); 392 | 393 | submit / r; 394 | library(randomForest) 395 | rf = randomForest(BWT ~ SMOKE + HT + LWT + PTL, data=birth,ntree=200,importance=TRUE) 396 | summary(rf) 397 | actual = birth$BWT 398 | pred = predict(rf,data=birth) 399 | actual.pred = cbind(actual,pred) 400 | colnames(actual.pred) <- c("Actual","Predicted") 401 | endsubmit; 402 | 403 | call ImportDataSetFromR("Rdata","actual.pred"); 404 | quit; 405 | -------------------------------------------------------------------------------- /code/SP4R01d02.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R01d02*/ 7 | 8 | /*Hello!*/ 9 | /*Welcome to SP4R!*/ 10 | 11 | /*This file creates the course library and data*/ 12 | 13 | /*Change this path to the appropriate location*/ 14 | %let path = s:\workshop; 15 | 16 | /* 17 | This course will use the library name sp4r. 18 | Each data set name will begin with the library name followed by a period. 19 | For example, to save a data set called 'dogs' in the SP4R library 20 | we will use the name sp4r.dogs 21 | */ 22 | libname sp4r "&path"; 23 | 24 | /* 25 | This statement runs the SP4R01d03.sas file 26 | and creates all the data for the course 27 | and stores it in the sp4r library. 28 | */ 29 | %include "&path\SP4R01d03.sas"; 30 | -------------------------------------------------------------------------------- /code/SP4R02d01.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R02d01*/ 7 | 8 | /*Part A*/ 9 | data sp4r.example_data; 10 | length First_Name $ 25 Last_Name $ 25; 11 | input First_Name $ Last_Name $ age height; 12 | datalines; 13 | Jordan Bakerman 27 68 14 | Bruce Wayne 35 70 15 | Walter White 51 70 16 | Henry Hill 65 66 17 | JeanClaude VanDamme 55 69 18 | ; 19 | run; 20 | 21 | /*Part B*/ 22 | data sp4r.example_data2; 23 | length First_Name $ 25 Last_Name $ 25; 24 | input First_Name $ Last_Name $ age height @@; 25 | datalines; 26 | Jordan Bakerman 27 68 Bruce Wayne 35 70 Walter White 51 70 27 | Henry Hill 65 66 JeanClaude VanDamme 55 69 28 | ; 29 | run; 30 | -------------------------------------------------------------------------------- /code/SP4R02d02.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R02d02*/ 7 | 8 | /*Import data using a DATA step*/ 9 | data sp4r.all_names; 10 | length First_Name $ 25 Last_Name $ 25; 11 | infile "&path\allnames.csv" dlm=','; 12 | input First_Name $ Last_Name $ age height; 13 | run; 14 | 15 | /***************************************************************************************************/ 16 | /*Import data using PROC IMPORT*/ 17 | proc import out=sp4r.baseball 18 | datafile= "&path\baseball.csv" DBMS=CSV REPLACE; 19 | getnames=yes; 20 | datarow=2; 21 | run; 22 | 23 | /*Rename the variables*/ 24 | data sp4r.baseball; 25 | set sp4r.baseball; 26 | rename nAtBat = At_Bats 27 | nHits = Hits 28 | nHome = Home_Runs 29 | nRuns = Runs 30 | nRBI = RBIs 31 | nError = Errors; 32 | run; 33 | 34 | /***************************************************************************************************/ 35 | /*Creating a SAS data set from delimited data by hand*/ 36 | data sp4r.example_data3; 37 | length First_name $ 25; 38 | infile datalines dlm='*'; 39 | input First_Name $ Last_Name $ age height; 40 | datalines; 41 | Jordan*Bakerman*27*68 42 | Bruce*Wayne*35*70 43 | Walter*White*51*70 44 | Henry*Hill*65*66 45 | Jean Claude*Van Damme*55*69 46 | ;run; 47 | -------------------------------------------------------------------------------- /code/SP4R02d03.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R02d03*/ 7 | 8 | data employees; 9 | input name $ bday :mmddyy8. @@; 10 | datalines; 11 | Jill 01011960 Jack 05111988 Joe 08221975 12 | ; 13 | run; 14 | 15 | proc print data=employees; 16 | run; 17 | 18 | data employees; 19 | input name $ bday :mmddyy8. @@; 20 | format bday mmddyy10.; 21 | label name="First Name" bday="Birthday"; 22 | datalines; 23 | Jill 01011960 Jack 05111988 Joe 08221975 24 | ; 25 | run; 26 | 27 | proc print data=employees label; 28 | run; 29 | -------------------------------------------------------------------------------- /code/SP4R02e01.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R02e01*/ 7 | 8 | Pluto 3 25 Black No 9 | Lizzie 10 43 Tan Yes 10 | Pesci 10 38 Brindle No 11 | -------------------------------------------------------------------------------- /code/SP4R02e02.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R02e02*/ 7 | 8 | Pluto#3#25#Black#No 9 | Lizzie#10#43#Tan#Yes 10 | Pesci#10#38#Brindle#No 11 | 12 | -------------------------------------------------------------------------------- /code/SP4R02e05.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R02e05*/ 7 | 8 | data sp4r.class; 9 | input student $ country $ grade bd @@; 10 | datalines; 11 | John Spain 95 12000 Mary Spain 82 12121 Alison France 98 12026 12 | Nadine Spain 77 12222 Josh Italy 61 12095 James France 45 12301 13 | William France 92 12284 Susan Italy 95 12079 14 | Charlie France 88 12234 Alice Italy 89 12014 Robert Italy 92 12025 15 | Emily Spain 87 12148 Arthur Italy 99 12052 Nancy France 70 12238 16 | Kristin France 65 12084 Sara Italy 49 12322 Ashley Spain 96 12299 17 | Aaron France 95 12052 Sean France 87 12254 Phil Italy 86 12036 18 | ; 19 | run; 20 | 21 | -------------------------------------------------------------------------------- /code/SP4R02s01.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R02s01*/ 7 | 8 | /*Part A*/ 9 | data sp4r.shelter; 10 | length Name $ 25 Color $ 10 Cats $ 3; 11 | input Name $ Age Weight Color $ Cats $; 12 | datalines; 13 | Pluto 3 25 Black No 14 | Lizzie 10 43 Tan Yes 15 | Pesci 10 38 Brindle No 16 | ; 17 | run; 18 | 19 | /*Part C*/ 20 | data sp4r.shelter2; 21 | length Name $ 25 Color $ 10 Cats $ 3; 22 | input Name $ Age Weight Color $ Cats $ @@; 23 | datalines; 24 | Pluto 3 25 Black No Lizzie 10 43 Tan Yes Pesci 10 38 Brindle No 25 | ; 26 | run; 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /code/SP4R02s02.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R02s02*/ 7 | 8 | data sp4r.shelter3; 9 | infile datalines dlm='#'; 10 | input Name $ Age Weight Color $ Cats $; 11 | datalines; 12 | Pluto#3#25#Black#No 13 | Lizzie#10#43#Tan#Yes 14 | Pesci#10#38#Brindle#No 15 | ;run; 16 | -------------------------------------------------------------------------------- /code/SP4R02s03.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R02s03*/ 7 | 8 | data sp4r.state_pop; 9 | length State $ 25; 10 | infile "&path\state_pop.txt" dlm='09'x; 11 | input State $ Population; 12 | run; 13 | -------------------------------------------------------------------------------- /code/SP4R02s04.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R02s04*/ 7 | 8 | proc import out = sp4r.state_pop2 9 | datafile = "&path\state_pop.xlsx" 10 | dbms = xlsx REPLACE; 11 | getnames = NO; 12 | sheet = "State_Pop_Data"; 13 | datarow = 1; 14 | run; 15 | 16 | data sp4r.state_pop2; 17 | set sp4r.state_pop2; 18 | rename A = State B = Population; 19 | run; 20 | -------------------------------------------------------------------------------- /code/SP4R02s05.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R02s05*/ 7 | 8 | /*Part A*/ 9 | proc format; 10 | value gradesformat 0-59='F' 60-69='D' 70-79='C' 80-89='B' 90-100='A'; 11 | run; 12 | 13 | /*Part B*/ 14 | data sp4r.class; 15 | input student $ country $ grade bd @@; 16 | label bd='Birthday'; 17 | format grade gradesformat. bd worddate.; 18 | datalines; 19 | John Spain 95 12000 Mary Spain 82 12121 Alison France 98 12026 20 | Nadine Spain 77 12222 Josh Italy 61 12095 James France 45 12301 21 | William France 92 12284 Susan Italy 95 12079 22 | Charlie France 88 12234 Alice Italy 89 12014 Robert Italy 92 12025 23 | Emily Spain 87 12148 Arthur Italy 99 12052 Nancy France 70 12238 24 | Kristin France 65 12084 Sara Italy 49 12322 Ashley Spain 96 12299 25 | Aaron France 95 12052 Sean France 87 12254 Phil Italy 86 12036 26 | ; 27 | run; 28 | 29 | /*Part C*/ 30 | proc print data= sp4r.class label; 31 | run; 32 | 33 | /*Part D*/ 34 | proc sql; 35 | select unique country from sp4r.class; 36 | quit; 37 | 38 | /*Part E*/ 39 | proc print data= sp4r.class; 40 | var student country grade; 41 | where grade>79 and country='France'; 42 | run; 43 | 44 | -------------------------------------------------------------------------------- /code/SP4R03s01.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R03s01*/ 7 | 8 | /*Part A*/ 9 | data sp4r.cars; 10 | set sp4r.cars; 11 | mpg_average = mean(mpg_city,mpg_highway); 12 | run; 13 | 14 | /*Part B*/ 15 | proc print data=sp4r.cars (obs=5); 16 | var mpg_city mpg_highway mpg_average; 17 | run; 18 | -------------------------------------------------------------------------------- /code/SP4R03s02.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R03s02*/ 7 | 8 | /*Part A*/ 9 | data sp4r.cars; 10 | length mpg_quality $ 6; 11 | set sp4r.cars; 12 | if mpg_average < 20 then mpg_quality='Low'; 13 | else if mpg_average < 30 then mpg_quality='Medium'; 14 | else mpg_quality='High'; 15 | run; 16 | 17 | /*Part B*/ 18 | proc print data=sp4r.cars (firstobs=65 obs=70); 19 | var mpg_average mpg_quality; 20 | run; 21 | -------------------------------------------------------------------------------- /code/SP4R03s03.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R03s03*/ 7 | 8 | /*Part A*/ 9 | proc fcmp outlib=work.functions.newfuncs; 10 | function tier(val) $; 11 | length newval $ 6; 12 | if val < 20 then newval = 'Low'; 13 | else if val <30 then newval='Medium'; 14 | else newval='High'; 15 | return(newval); 16 | endsub; 17 | quit; 18 | 19 | /*Part B*/ 20 | options cmplib=work.functions; 21 | data sp4r.cars; 22 | set sp4r.cars; 23 | mpg_quality2=tier(mpg_average); 24 | run; 25 | 26 | /*Part C*/ 27 | proc print data=sp4r.cars (firstobs=65 obs=70); 28 | var mpg_average mpg_quality mpg_quality2; 29 | run; 30 | -------------------------------------------------------------------------------- /code/SP4R03s04.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R03s04*/ 7 | 8 | /*Part A*/ 9 | proc sql; 10 | create table make as select unique make from sp4r.cars; 11 | create table type as select unique type from sp4r.cars; 12 | create table origin as select unique origin from sp4r.cars; 13 | quit; 14 | 15 | /*Part B*/ 16 | data sp4r.mylist; 17 | merge make type origin; 18 | run; 19 | 20 | /*Part C*/ 21 | proc print data= sp4r.mylist; 22 | run; 23 | -------------------------------------------------------------------------------- /code/SP4R03s05.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R03s05*/ 7 | 8 | /*Part A*/ 9 | data sp4r.sports(keep= make type msrp); 10 | set sp4r.cars; 11 | where type='Sports' and msrp>100000; 12 | run; 13 | 14 | /*Part B*/ 15 | data sp4r.suv(keep= make type msrp); 16 | set sp4r.cars; 17 | where type='SUV' and msrp>60000; 18 | run; 19 | 20 | /*Part C*/ 21 | data sp4r.expensive; 22 | set sp4r.sports sp4r.suv; 23 | run; 24 | 25 | proc print data= sp4r.expensive; 26 | run; 27 | -------------------------------------------------------------------------------- /code/SP4R04d01.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R04d01*/ 7 | 8 | /*Part A*/ 9 | data sp4r.random (drop=i); 10 | call streaminit(123); 11 | do i=1 to 10; 12 | rnorm = rand('Normal',20,5); 13 | rbinom = rand('Binomial',.25,1); 14 | runif = rand('Uniform')*10; 15 | rexp = rand('Exponential')*5; 16 | output; 17 | end; 18 | run; 19 | 20 | proc print data=sp4r.random; 21 | run; 22 | 23 | /*Part B*/ 24 | data sp4r.random; 25 | call streaminit(123); 26 | set sp4r.random; 27 | rgeom = rand('Geometric',.1); 28 | run; 29 | 30 | proc print data=sp4r.random; 31 | run; 32 | 33 | /*Part C*/ 34 | data sp4r.doloop (drop=j); 35 | call streaminit(123); 36 | do group=1 to 5; 37 | do j=1 to 3; 38 | rpois = rand('Poisson',25); 39 | rbeta = rand('Beta',.5,.5); 40 | seq+1; 41 | output; 42 | end; 43 | end; 44 | run; 45 | 46 | proc print data=sp4r.doloop; 47 | run; 48 | 49 | /*Part D*/ 50 | data sp4r.quants; 51 | do q=-3 to 3 by .5; 52 | pdf = pdf('Normal',q,0,1); 53 | cdf = cdf('Normal',q,0,1); 54 | quantile = quantile('Normal',cdf,0,1); 55 | output; 56 | end; 57 | run; 58 | 59 | proc print data=sp4r.quants; 60 | run; 61 | -------------------------------------------------------------------------------- /code/SP4R04d02.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R04d02*/ 7 | 8 | /*Part A*/ 9 | data sp4r.hist_data; 10 | call streaminit(123); 11 | do i=1 to 1000; 12 | x = rand('exponential')*10; 13 | output; 14 | end; 15 | run; 16 | 17 | proc sgplot data=sp4r.hist_data; 18 | histogram x; 19 | run; 20 | 21 | proc sgplot data=sp4r.hist_data; 22 | histogram x / binwidth=1; 23 | density x / type=normal; 24 | density x / type=kernel; 25 | run; 26 | 27 | /*Part B*/ 28 | data sp4r.boxplot_data (drop=rep); 29 | call streaminit(123); 30 | do group=1 to 3; 31 | do rep=1 to 100; 32 | response = rand('exponential')*10; 33 | output; 34 | end; 35 | end; 36 | run; 37 | 38 | proc sgplot data=sp4r.boxplot_data; 39 | hbox response; 40 | run; 41 | 42 | proc sgplot data=sp4r.boxplot_data; 43 | hbox response / category=group; 44 | run; 45 | 46 | /*Part C*/ 47 | data sp4r.sales; 48 | call streaminit(123); 49 | do month=1 to 12; 50 | revenue = rand('Normal',10000,5000); 51 | output; 52 | end; 53 | run; 54 | 55 | proc sgplot data=sp4r.sales; 56 | vbar month / response=revenue; 57 | run; 58 | 59 | /*Part D*/ 60 | data sp4r.series_data (keep=x y1 y2); 61 | call streaminit(123); 62 | do x=1 to 30; 63 | beta01 = 10; 64 | beta11 = 1; 65 | y1 = beta01 + beta11*x + rand('Normal',0,5); 66 | beta02 = 35; 67 | beta12 = .5; 68 | y2 = beta02 + beta12*x + rand('Normal',0,5); 69 | output; 70 | end; 71 | run; 72 | 73 | proc sgplot data=sp4r.series_data; 74 | scatter x=x y=y1; 75 | scatter x=x y=y2; 76 | run; 77 | 78 | proc sgplot data=sp4r.series_data; 79 | series x=x y=y1; 80 | series x=x y=y2; 81 | run; 82 | 83 | proc sgplot data=sp4r.series_data; 84 | series x=x y=y1; 85 | scatter x=x y=y1; 86 | series x=x y=y2; 87 | scatter x=x y=y2; 88 | run; 89 | 90 | /*Part E*/ 91 | proc sgplot data=sp4r.series_data; 92 | reg x=x y=y1 / clm cli; 93 | reg x=x y=y2 / clm cli; 94 | run; 95 | -------------------------------------------------------------------------------- /code/SP4R04d03.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R04d03*/ 7 | 8 | /*Part A*/ 9 | data sp4r.sales; 10 | call streaminit(123); 11 | do month=1 to 12; 12 | revenue = rand('Normal',10000,1000); 13 | revenue_2 = rand('Normal',13000,500); 14 | output; 15 | end; 16 | run; 17 | 18 | /*Part B*/ 19 | proc sgplot data=sp4r.sales; 20 | series x=month y=revenue / legendlabel='Company A' 21 | lineattrs=(color=blue pattern=dash); 22 | series x=month y=revenue_2 / legendlabel='Company B' 23 | lineattrs=(color=red pattern=dash); 24 | 25 | title 'Monthly Sales of Company A and B for 2015'; 26 | xaxis label="Month" values=(1 to 12 by 1); 27 | yaxis label="Revenue for 2015"; 28 | inset "Jordan Bakerman" / position=bottomright; 29 | refline 6.5 / transparency= 0.5 axis=x; 30 | refline 11000 / transparency= 0.5; 31 | run; 32 | title; 33 | 34 | /*Part C*/ 35 | proc sgplot data=sp4r.sales; 36 | series x=month y=revenue / legendlabel='Company A' name='Company A' 37 | lineattrs=(color=blue pattern=dash); 38 | scatter x=month y=revenue / markerattrs=(color=blue 39 | symbol=circlefilled); 40 | series x=month y=revenue_2 / legendlabel='Company B' 41 | name='Company B' lineattrs=(color=red pattern=dash); 42 | scatter x=month y=revenue_2 / markerattrs=(color=red 43 | symbol=circlefilled); 44 | 45 | title 'Monthly Sales of Company A and B for 2015'; 46 | xaxis label="Month" values=(1 to 12 by 1); 47 | yaxis label="Revenue for 2015" min=8000 max=14000; 48 | inset "Jordan Bakerman" / position=bottomright; 49 | refline 11000 / transparency= 0.5; 50 | refline 6.5 / transparency= 0.5 axis=x; 51 | keylegend 'Company A' 'Company B'; 52 | run; 53 | title; 54 | -------------------------------------------------------------------------------- /code/SP4R04d04.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R04d04*/ 7 | 8 | /*Part A*/ 9 | data sp4r.multi; 10 | call streaminit(123); 11 | do Sex='F', 'M'; 12 | do j=1 to 1000; 13 | if sex='F' then height = rand('Normal',66,2); 14 | else height = rand('Normal',72,2); 15 | output; 16 | end; 17 | end; 18 | run; 19 | 20 | /*Part B*/ 21 | proc sgpanel data=sp4r.multi; 22 | panelby sex; 23 | histogram height; 24 | density height / type=normal; 25 | title 'Heights of Males and Females'; 26 | colaxis label='Height'; 27 | run; 28 | title; 29 | 30 | /*Part C*/ 31 | ods layout Start rows=1 columns=3 row_height=(1in) column_gutter=0; 32 | 33 | ods region row=1 column=1; 34 | proc sgplot data=sp4r.multi (where= (sex='F')); 35 | histogram height / binwidth=.5; 36 | title 'Histogram of Female Heights'; 37 | run; 38 | title; 39 | 40 | ods region row=1 column=2; 41 | proc sgplot data=sp4r.multi (where= (sex='F')); 42 | density height / type=kernel; 43 | title 'Density Estimate of Female Heights'; 44 | run; 45 | title; 46 | 47 | ods region row=1 column=3; 48 | proc sgplot data=sp4r.multi (where= (sex='F')); 49 | hbox height; 50 | title 'Boxplot of Female Hieghts'; 51 | run; 52 | title; 53 | 54 | ods layout end; 55 | -------------------------------------------------------------------------------- /code/SP4R04e02.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R04e02*/ 7 | 8 | data test; 9 | do i=1 to 2; 10 | output; 11 | end; 12 | run; 13 | 14 | proc print data=test; 15 | run; 16 | 17 | data test; 18 | set test; 19 | do j=1 to 5; 20 | output; 21 | end; 22 | run; 23 | 24 | proc print data=test; 25 | run; 26 | -------------------------------------------------------------------------------- /code/SP4R04s01.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R04s01*/ 7 | 8 | /*Part A*/ 9 | data sp4r.random; 10 | call streaminit(123); 11 | do i=1 to 10; 12 | rt = rand('T',5); 13 | rf = rand('F',3,4); 14 | ru = int(rand('Uniform')*10); 15 | output; 16 | end; 17 | run; 18 | 19 | proc print data=sp4r.random; 20 | run; 21 | 22 | /*Part B*/ 23 | data sp4r.random (drop=j); 24 | call streaminit(123); 25 | do class=1 to 2; 26 | do j=1 to 5; 27 | sequence + 1; 28 | rt = rand('T',5); 29 | rf = rand('F',3,4); 30 | ru = int(rand('Uniform')*10); 31 | output; 32 | end; 33 | end; 34 | run; 35 | 36 | proc print data=sp4r.random; 37 | run; 38 | 39 | /*Part C*/ 40 | data random; 41 | do i=1 to 2; 42 | output; 43 | end; 44 | run; 45 | 46 | proc print data=random; 47 | run; 48 | 49 | data random; 50 | set random; 51 | do j=1 to 5; 52 | output; 53 | end; 54 | run; 55 | 56 | proc print data=random; 57 | run; 58 | -------------------------------------------------------------------------------- /code/SP4R04s02.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R04s02*/ 7 | 8 | data sp4r.random; 9 | do q=0 to 10 by 1; 10 | pdf = pdf('Binomial',q,.8,10); 11 | cdf = cdf('Binomial',q,.8,10); 12 | quantile = quantile('Binomial',cdf,.8,10); 13 | output; 14 | end; 15 | run; 16 | 17 | proc print data=sp4r.random; 18 | run; 19 | -------------------------------------------------------------------------------- /code/SP4R04s03.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R04s03*/ 7 | 8 | /*Part A*/ 9 | data sp4r.hist; 10 | call streaminit(123); 11 | do i=1 to 1000; 12 | rchisq = rand('chisquare',20); 13 | output; 14 | end; 15 | run; 16 | 17 | /*Part B*/ 18 | proc sgplot data=sp4r.hist; 19 | histogram rchisq / binwidth=1 scale=count; 20 | density rchisq / type=normal; 21 | density rchisq / type=kernel; 22 | title 'My Random Chi-Square Distribution'; 23 | xaxis label='Random Chi-Square Deviates' min=5 max=40; 24 | run; 25 | title; 26 | -------------------------------------------------------------------------------- /code/SP4R04s04.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R04s04*/ 7 | 8 | /*Part A*/ 9 | data sp4r.simple_lin (keep=x y); 10 | call streaminit(123); 11 | do x=1 to 30; 12 | beta01 = 25; 13 | beta11 = 1; 14 | y = beta01 + beta11*x + rand('Normal',0,5); 15 | output; 16 | end; 17 | run; 18 | 19 | /*Part B*/ 20 | proc sgplot data=sp4r.simple_lin; 21 | scatter x=x y=y / legendlabel='Scatter' name='Scatter' 22 | markerattrs=(color=blue symbol=starfilled); 23 | reg x=x y=y / legendlabel='Line of Best Fit' name='Line' 24 | lineattrs=(color=red pattern=dot); 25 | 26 | title 'My Scatter Plot'; 27 | xaxis label='X Values' min=0 max=31; 28 | yaxis label='Y Values' min=15 max=65; 29 | keylegend 'Scatter' 'Line'; 30 | run; 31 | title; 32 | 33 | /*Part C*/ 34 | proc sgplot data=sp4r.simple_lin; 35 | needle x=x y=y / legendlabel='Needle' name='Needle' markerattrs=(color=blue symbol=starfilled); 36 | pbspline x=x y=y / legendlabel='Line of Best Fit' name='Line' 37 | lineattrs=(color=red pattern=dot); 38 | 39 | title 'My Needle Plot'; 40 | xaxis label='X Values' min=0 max=31; 41 | yaxis label='Y Values' min=15 max=65; 42 | keylegend 'Needle' 'Line'; 43 | run; 44 | title; 45 | -------------------------------------------------------------------------------- /code/SP4R04s05.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R04s05*/ 7 | 8 | /*Part A*/ 9 | data sp4r.bubble; 10 | call streaminit(123); 11 | do group=1 to 2; 12 | do x=1 to 20; 13 | y = rand('Exponential'); 14 | z = rand('binomial',.5,5); 15 | output; 16 | end; 17 | end; 18 | run; 19 | 20 | /*Part B*/ 21 | proc sgplot data=sp4r.bubble; 22 | bubble x=x y=y size=z / group=group; 23 | 24 | title 'My Bubble Plot'; 25 | xaxis label='X Values'; 26 | yaxis label='Y Values'; 27 | run; 28 | -------------------------------------------------------------------------------- /code/SP4R04s06.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R04s06*/ 7 | 8 | /*Part A*/ 9 | data sp4r.random; 10 | call streaminit(123); 11 | do i=1 to 300; 12 | x = rand('Normal'); 13 | y1 = x + rand('Normal'); 14 | y2 = 5*x + rand('Normal'); 15 | output; 16 | end; 17 | run; 18 | 19 | /*Part B*/ 20 | proc sgscatter data=sp4r.random; 21 | matrix x y1 y2 / diagonal=(histogram kernel); 22 | title 'Scatter Plot Matrix'; 23 | run; 24 | title; 25 | 26 | /*Part C*/ 27 | proc sgscatter data=sp4r.random; 28 | plot (y1 y2) * x / reg; 29 | title 'Scatter Plots'; 30 | run; 31 | title; 32 | 33 | /*Part D*/ 34 | proc sgscatter; 35 | compare y=(y1 y2) x=x / reg; 36 | title 'Scatter Plots'; 37 | run; 38 | title; 39 | -------------------------------------------------------------------------------- /code/SP4R04s07.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R04s07*/ 7 | 8 | /*Part A*/ 9 | data sp4r.random; 10 | call streaminit(123); 11 | do year=1 to 2; 12 | do j=1 to 300; 13 | x = rand('Normal'); 14 | if year=1 then y = x + rand('Normal'); 15 | if year=2 then y = 5*x + rand('Normal'); 16 | output; 17 | end; 18 | end; 19 | run; 20 | 21 | /*Part B*/ 22 | proc sgpanel data=sp4r.random; 23 | panelby year; 24 | reg x=x y=y; 25 | title 'Regression Panels'; 26 | run; 27 | title; 28 | -------------------------------------------------------------------------------- /code/SP4R05d01.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R05d01*/ 7 | 8 | /*Part A*/ 9 | proc contents data=sp4r.ameshousing varnum; 10 | run; 11 | 12 | /*Part B*/ 13 | proc univariate data=sp4r.ameshousing; 14 | var saleprice; 15 | histogram saleprice / normal kernel; 16 | inset n mean std / position=ne; 17 | qqplot saleprice / normal(mu=est sigma=est); 18 | run; 19 | -------------------------------------------------------------------------------- /code/SP4R05d02.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R05d02*/ 7 | 8 | /*Part A*/ 9 | ods trace on; 10 | proc univariate data=sp4r.ameshousing; 11 | var saleprice; 12 | qqplot saleprice / normal(mu=est sigma=est); 13 | run; 14 | ods trace off; 15 | 16 | /*Part B*/ 17 | ods select basicmeasures qqplot; 18 | proc univariate data=sp4r.ameshousing; 19 | var saleprice; 20 | qqplot saleprice / normal(mu=est sigma=est); 21 | run; 22 | -------------------------------------------------------------------------------- /code/SP4R05d03.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R05d03*/ 7 | 8 | /*Part A*/ 9 | ods select basicmeasures; 10 | ods output basicmeasures = sp4r.SalePrice_BasicMeasures; 11 | proc univariate data=sp4r.ameshousing; 12 | var saleprice; 13 | run; 14 | 15 | proc print data=sp4r.saleprice_basicmeasures; 16 | run; 17 | 18 | /*Part B*/ 19 | proc univariate data=sp4r.ameshousing; 20 | var saleprice; 21 | output out=sp4r.stats mean=saleprice_mean pctlpts= 40, 45, 50, 55, 60 22 | pctlpre=saleprice_; 23 | run; 24 | 25 | proc print data=sp4r.stats; 26 | run; 27 | 28 | /*Part C*/ 29 | proc means data=sp4r.ameshousing; 30 | var saleprice garage_area; 31 | output out=sp4r.stats mean(saleprice)=sp_mean median(garage_area)=ga_med; 32 | run; 33 | 34 | proc print data=sp4r.stats; 35 | run; 36 | 37 | /*Part D*/ 38 | proc means data=sp4r.ameshousing; 39 | var saleprice garage_area; 40 | output out=sp4r.stats mean= std= / autoname; 41 | run; 42 | 43 | proc print data=sp4r.stats; 44 | run; 45 | -------------------------------------------------------------------------------- /code/SP4R05d04.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R05d04*/ 7 | 8 | /*Part A*/ 9 | proc means data=sp4r.ameshousing; 10 | var saleprice; 11 | output out=sp4r.stats mean=sp_mean std=sp_sd; 12 | run; 13 | 14 | proc sql; 15 | select sp_mean into :sp_mean from sp4r.stats; 16 | select sp_sd into :sp_sd from sp4r.stats; 17 | quit; 18 | 19 | /*Part B*/ 20 | data sp4r.ameshousing; 21 | set sp4r.ameshousing; 22 | sp_stan = (saleprice - &sp_mean) / &sp_sd; 23 | run; 24 | 25 | proc print data=sp4r.ameshousing (obs=6); 26 | var saleprice sp_stan; 27 | run; 28 | 29 | proc means data=sp4r.ameshousing mean std; 30 | var saleprice sp_stan; 31 | run; 32 | 33 | /*Part C*/ 34 | proc contents data=sp4r.cars varnum out=carscontents; 35 | run; 36 | 37 | proc print data=carscontents; 38 | var name type; 39 | run; 40 | 41 | /*Part D*/ 42 | proc sql; 43 | select distinct name into: vars_cont separated by ' ' from carscontents where type=1; 44 | select distinct name into: vars_cat separated by ' ' from carscontents where type=2; 45 | quit; 46 | 47 | %put The continuous variables are &vars_cont and the categorical variables are &vars_cat; 48 | -------------------------------------------------------------------------------- /code/SP4R05d05.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R05d05*/ 7 | 8 | /*Part A*/ 9 | %macro mymac(dist,param1,param2=,n=100,stats=no,plot=no); 10 | 11 | /*Part B*/ 12 | %if &dist= %then %do; 13 | %put Dist is a required argument; 14 | %return; 15 | %end; 16 | 17 | %if ¶m1= %then %do; 18 | %put Param1 is a required argument; 19 | %return; 20 | %end; 21 | 22 | /*Part C*/ 23 | %if ¶m2= %then %do; 24 | data random (drop=i); 25 | do i=1 to &n; 26 | y=rand("&dist",¶m1); 27 | x+1; 28 | output; 29 | end; 30 | run; 31 | %end; 32 | 33 | %else %do; 34 | data random (drop=i); 35 | do i=1 to &n; 36 | y=rand("&dist",¶m1,¶m2); 37 | x+1; 38 | output; 39 | end; 40 | run; 41 | %end; 42 | 43 | /*Part D*/ 44 | %if %upcase(&stats)=YES %then %do; 45 | proc means data=random mean std; 46 | var y; 47 | run; 48 | %end; 49 | 50 | /*Part E*/ 51 | %if %upcase(&plot)=YES %then %do; 52 | proc sgplot data=random; 53 | histogram y / binwidth=1; 54 | density y / type=kernel; 55 | run; 56 | %end; 57 | 58 | %mend; 59 | 60 | /*Part F*/ 61 | %mymac(param1=0.2,stats=yes) 62 | 63 | /*Part G*/ 64 | %mymac(dist=Geometric,param1=0.2,param2=,stats=yes) 65 | 66 | /*Part H*/ 67 | options mprint; 68 | %mymac(dist=Normal,param1=100,param2=10,n=1000,plot=yes) 69 | -------------------------------------------------------------------------------- /code/SP4R05d06.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R05d06*/ 7 | 8 | %macro myappend(start,stop); 9 | %do year=&start %to &stop; 10 | proc import datafile="&path\sales_&year..csv" out=sp4r.sales_&year dbms=csv replace; 11 | run; 12 | 13 | proc append base=sp4r.sales_all data=sp4r.sales_&year; 14 | run; 15 | 16 | proc datasets library=sp4r noprint; 17 | delete sales_&year; 18 | quit; 19 | %end; 20 | %mend; 21 | 22 | options mprint; 23 | %myappend(2000,2009) 24 | 25 | /*Why did we use a double period to specify the DATAFILE above?*/ 26 | %let mypath = s:workshop\; 27 | %put &mypathmydata.csv; 28 | %put &mypath.mydata.csv; 29 | 30 | %let mydata = sales_data; 31 | %put &mydata.csv; 32 | %put &mydata..csv; 33 | -------------------------------------------------------------------------------- /code/SP4R05e03.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R05e03*/ 7 | 8 | data _NULL_; 9 | x=-3; 10 | df=5; 11 | p=(1-probt(abs(x),df))*2; 12 | call symputx('sig_level',p); 13 | run; 14 | 15 | %put The significance level for the two-tailed t test is &sig_level; 16 | -------------------------------------------------------------------------------- /code/SP4R05e04.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R05e04*/ 7 | 8 | /*Part A*/ 9 | %macro mystats(dt,freq=no,corr=no,means=no,opts=,scatter=no); 10 | 11 | 12 | 13 | /*Part B*/ 14 | 15 | 16 | 17 | /*Part C*/ 18 | 19 | 20 | 21 | /*Part D*/ 22 | 23 | 24 | 25 | /*Part E*/ 26 | 27 | 28 | 29 | %mend; 30 | 31 | /*Part F*/ 32 | 33 | 34 | 35 | /*Part G*/ 36 | 37 | 38 | -------------------------------------------------------------------------------- /code/SP4R05s01.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R05s01*/ 7 | 8 | /*Part A*/ 9 | proc freq data=sp4r.ameshousing; 10 | tables central_air house_style / plots=freqplot; 11 | run; 12 | 13 | /*Part B*/ 14 | ods select pearsoncorr; 15 | proc corr data=sp4r.ameshousing; 16 | var saleprice garage_area basement_area gr_liv_area; 17 | run; 18 | 19 | /*Part C*/ 20 | ods output summary=summary_table; 21 | proc means data=sp4r.ameshousing p10 median p90; 22 | var saleprice gr_liv_area; 23 | class yr_sold; 24 | run; 25 | 26 | proc print data=summary_table; 27 | run; 28 | 29 | /*Part D*/ 30 | proc univariate data=sp4r.ameshousing; 31 | var gr_liv_area; 32 | histogram gr_liv_area / normal kernel; 33 | qqplot gr_liv_area / normal(mu=est sigma=est); 34 | output out=gr_percs pctlpts= 40 to 60 by 2 pctlpre=gr_; 35 | run; 36 | 37 | proc print data=gr_percs; 38 | run; 39 | -------------------------------------------------------------------------------- /code/SP4R05s02.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R05s02*/ 7 | 8 | /*Part A*/ 9 | proc means data=sp4r.ameshousing; 10 | var saleprice; 11 | output out=sp4r.stats median=sp_med; 12 | run; 13 | 14 | /*Part B*/ 15 | proc sql; 16 | select sp_med into :sp_med from sp4r.stats; 17 | quit; 18 | 19 | /*Part C*/ 20 | data sp4r.ameshousing; 21 | set sp4r.ameshousing; 22 | if saleprice > &sp_med then sp_bin = 1; 23 | else sp_bin = 0; 24 | run; 25 | 26 | proc freq data=sp4r.ameshousing; 27 | tables sp_bin; 28 | run; 29 | 30 | -------------------------------------------------------------------------------- /code/SP4R05s03.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R05s03*/ 7 | 8 | /*Part A*/ 9 | data _NULL_; 10 | x=-3; 11 | df=5; 12 | p=(1-probt(abs(x),df))*2; 13 | call symputx('sig_level',p); 14 | run; 15 | 16 | %put The significance level for the two-tailed t test is &sig_level; 17 | 18 | /*Part B*/ 19 | proc means data=sp4r.ameshousing; 20 | var saleprice; 21 | output out=stats median=sp_med; 22 | run; 23 | 24 | data _null_; 25 | set stats; 26 | call symputx('med',sp_med); 27 | run; 28 | 29 | %put The median of the Sale Price variable is &med; 30 | 31 | /*Part A*/ 32 | -------------------------------------------------------------------------------- /code/SP4R05s04.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R05s04*/ 7 | 8 | /*Part A*/ 9 | %macro mystats(dt,freq=no,corr=no,means=no,opts=,scatter=no); 10 | 11 | %if &dt= %then %do; 12 | %put dt is a required argument; 13 | %return; 14 | %end; 15 | 16 | /*Part B*/ 17 | proc contents data=&dt varnum out=dtcontents; 18 | run; 19 | 20 | proc sql; 21 | select distinct name into: vars_cont separated by ' ' 22 | from dtcontents where type=1; 23 | select distinct NAME into: vars_cat separated by ' ' 24 | from dtcontents where type=2; 25 | quit; 26 | 27 | /*Part C*/ 28 | %if %upcase(&freq)=YES %then %do; 29 | proc freq data=&dt; 30 | tables &vars_cat; 31 | run; 32 | %end; 33 | 34 | /*Part D*/ 35 | %if %upcase(&means)=YES %then %do; 36 | proc means data=&dt &opts; 37 | var &vars_cont; 38 | run; 39 | %end; 40 | 41 | /*Part E*/ 42 | %if %upcase(&scatter)=YES %then %do; 43 | proc sgscatter data=&dt; 44 | matrix &vars_cont; 45 | run; 46 | %end; 47 | %mend; 48 | 49 | /*Part F*/ 50 | %mystats(sp4r.cars,freq=yes) 51 | 52 | /*Part G*/ 53 | %mystats(sp4r.cars,means=yes,opts=mean median maxdec=2,scatter=yes) 54 | -------------------------------------------------------------------------------- /code/SP4R05s05.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R05s05*/ 7 | 8 | /*Part A*/ 9 | %macro myimport(firstyear,lastyear); 10 | %do i=&firstyear %to &lastyear; 11 | proc import datafile = "&path\amesbyyear.xlsx" 12 | out = sp4r.year&i 13 | dbms = xlsx REPLACE; 14 | getnames = yes; 15 | sheet = "&i"; 16 | datarow = 2; 17 | run; 18 | %end; 19 | %mend; 20 | 21 | /*Part B*/ 22 | options mprint; 23 | %myimport(2006,2010) 24 | -------------------------------------------------------------------------------- /code/SP4R06d01.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06d01*/ 7 | 8 | /*Part A*/ 9 | proc sgscatter data=sp4r.ameshousing; 10 | plot saleprice * (gr_liv_area age_sold) / reg; 11 | run; 12 | 13 | /*Part B*/ 14 | ods select anova fitstatistics parameterestimates residualplot; 15 | proc reg data=sp4r.ameshousing; 16 | model saleprice = gr_liv_area age_sold; 17 | output out=sp4r.out predicted=pred residual=res rstudent=rstudent; 18 | run;quit; 19 | 20 | /*Part C*/ 21 | proc sgplot data=sp4r.out; 22 | scatter x=pred y=res; 23 | refline 0 / axis=y; 24 | run; 25 | 26 | /*Part D*/ 27 | ods select basicmeasures histogram qqplot; 28 | proc univariate data=sp4r.out; 29 | var res; 30 | histogram res / normal kernel; 31 | qqplot res / normal(mu=est sigma=est); 32 | run; 33 | 34 | /*Part E*/ 35 | proc reg data=sp4r.ameshousing; 36 | model saleprice = gr_liv_area age_sold; 37 | store mymod; 38 | run;quit; 39 | 40 | proc plm restore=mymod; 41 | score data=sp4r.newdata_ames_reg out=sp4r.pred_newdata predicted; 42 | run; 43 | 44 | /*Part F*/ 45 | proc print data=sp4r.pred_newdata; 46 | var saleprice gr_liv_area age_sold predicted; 47 | run; 48 | -------------------------------------------------------------------------------- /code/SP4R06d02.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06d02*/ 7 | 8 | /*Part A*/ 9 | proc print data=sp4r.paper; 10 | run; 11 | 12 | /*Part B*/ 13 | proc sgplot data=sp4r.paper; 14 | reg x=amount y=strength / legendlabel="Linear"; 15 | reg x=amount y=strength / degree=2 legendlabel="Quadratic"; 16 | reg x=amount y=strength / degree=3 legendlabel="Cubic"; 17 | title 'Polynomial Plot'; 18 | run; 19 | title; 20 | 21 | /*Part C*/ 22 | data sp4r.paper; 23 | set sp4r.paper; 24 | amount_sq = amount*amount; 25 | amount_cub = amount*amount*amount; 26 | run; 27 | 28 | proc reg data=sp4r.paper; 29 | model strength = amount amount_sq amount_cub; 30 | run;quit; 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /code/SP4R06d03.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06d03*/ 7 | 8 | proc glm data=sp4r.ameshousing plots=diagnostics; 9 | class heating_qc (ref='Fa') central_air (ref='N'); 10 | model saleprice = heating_qc|central_air / solution; 11 | *Alternative MODEL statement syntax; 12 | *model saleprice = heating_qc central_air heating_qc*central_air; 13 | lsmeans heating_qc|central_air; 14 | estimate 'Main Effect EX vs GD' heating_qc 1 -1 0 0 15 | heating_qc*central_air .5 .5 -.5 -.5 0 0 0 0/ e; 16 | run;quit; 17 | -------------------------------------------------------------------------------- /code/SP4R06d04.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06d04*/ 7 | 8 | proc sql; 9 | select mean(gr_liv_area) into :gr_mean from sp4r.ameshousing; 10 | quit; 11 | 12 | proc glm data=sp4r.ameshousing plots=diagnostics; 13 | class heating_qc (ref='Fa'); 14 | model saleprice = heating_qc|gr_liv_area / solution clparm; 15 | lsmeans heating_qc / at gr_liv_area=&gr_mean pdiff adjust=tukey cl; 16 | estimate 'My Estimate' intercept 1 heating_qc 1 0 0 0 17 | gr_liv_area &gr_mean heating_qc*gr_liv_area &gr_mean; 18 | run;quit; 19 | -------------------------------------------------------------------------------- /code/SP4R06d05.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06d05*/ 7 | 8 | /*Part A*/ 9 | %let cont_vars = lot_area gr_liv_area garage_area basement_area deck_porch_area age_sold; 10 | %let cat_vars = heating_qc central_air fireplaces lot_shape_2; 11 | 12 | proc glmselect data=sp4r.ameshousing2 plots=all seed=802; 13 | class &cat_vars; 14 | model saleprice = &cont_vars &cat_vars / selection=lasso(choose=validate stop=none); 15 | partition fraction(validate=0.5); 16 | store mymod; 17 | run; 18 | 19 | /*Part B*/ 20 | proc plm restore=mymod; 21 | score data=sp4r.newdata_ames_reg out=sp4r.pred_newdata 22 | predicted; 23 | run; 24 | 25 | /*Part C*/ 26 | proc print data=sp4r.pred_newdata; 27 | var saleprice predicted; 28 | run; 29 | 30 | -------------------------------------------------------------------------------- /code/SP4R06d06.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06d06*/ 7 | 8 | /*Part A*/ 9 | proc glmselect data=sp4r.paper outdesign=sp4r.des; 10 | effect amount_pol = polynomial(amount / degree=5); 11 | model strength = amount_pol / selection=forward select=sl sle=.05 12 | hierarchy=single; 13 | run;quit; 14 | 15 | /*Part B*/ 16 | proc print data=sp4r.des; 17 | run; 18 | 19 | proc reg data=sp4r.des; 20 | model strength = &_glsmod; 21 | run;quit; 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /code/SP4R06d07.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06d07*/ 7 | 8 | /*Part A*/ 9 | proc logistic data=sp4r.ameshousing plots(only)=(effect oddsratio roc); 10 | class fireplaces(ref='0') lot_shape_2(ref='Regular') / param=ref; 11 | model bonus(event='1') = basement_area fireplaces lot_shape_2 12 | / clodds=wald; 13 | units basement_area = 100; 14 | estimate 'my estimate' intercept 1 basement_area 1000 15 | fireplaces 1 0 lot_shape_2 1 / e alpha=.05 ilink; 16 | output out=sp4r.out p=pred; 17 | store mymod; 18 | run; 19 | 20 | proc print data=sp4r.out (obs=5); 21 | var bonus basement_area fireplaces lot_shape_2 pred; 22 | run; 23 | 24 | /*Part B*/ 25 | proc plm restore=mymod; 26 | score data=sp4r.newdata_ames_logistic out=sp4r.pred_newdata 27 | predicted lclm uclm /ilink; 28 | run; 29 | 30 | /*Part C*/ 31 | proc print data=sp4r.pred_newdata; 32 | var bonus basement_area fireplaces lot_shape_2 predicted lclm uclm; 33 | run; 34 | -------------------------------------------------------------------------------- /code/SP4R06d08.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06d08*/ 7 | 8 | /*Part A*/ 9 | proc sgplot data=sp4r.crab; 10 | histogram satellites; 11 | density satellites / type=kernel; 12 | run; 13 | 14 | proc means data=sp4r.crab; 15 | var satellites width weight; 16 | run; 17 | 18 | proc freq data=sp4r.crab; 19 | tables satellites color spine; 20 | run; 21 | 22 | /*Part B*/ 23 | proc genmod data=sp4r.crab plots=resraw; 24 | class color(param=ref ref='1') spine(param=ref ref='1'); 25 | model satellites = width weight color spine 26 | / dist=poi link=log type3; 27 | estimate 'my estimate' intercept 1 width 25 weight 2.5 28 | color 1 0 0 spine 1 0 / e exp alpha=.05; 29 | output out=sp4r.out p=pred resraw=res; 30 | run; 31 | 32 | proc sgplot data=sp4r.out; 33 | scatter y=res x=pred; 34 | run; 35 | 36 | /*Part C*/ 37 | proc genmod data=sp4r.crab plots=resraw; 38 | class color(param=ref ref='1') spine(param=ref ref='1'); 39 | model satellites = width weight color spine 40 | / dist=negbin link=log type3; 41 | estimate 'my estimate' intercept 1 width 25 weight 2.5 42 | color 1 0 0 spine 1 0 / e exp alpha=.05; 43 | output out=sp4r.out p=pred resraw=res; 44 | store mymod; 45 | run; 46 | 47 | /*Part D*/ 48 | data sp4r.newcrab; 49 | input Color Spine Width Satellites Weight; 50 | datalines; 51 | 2 2 25 0 2.5 52 | ;run; 53 | 54 | proc plm restore=mymod; 55 | score data=sp4r.newcrab out=sp4r.scores / ilink; 56 | run; 57 | 58 | proc print data=sp4r.scores; 59 | run; 60 | -------------------------------------------------------------------------------- /code/SP4R06d09.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06d09*/ 7 | 8 | /*Part A*/ 9 | proc sgplot data=sp4r.grass; 10 | vline variety / group=method stat=mean response=yield; 11 | run; 12 | 13 | /*Part B*/ 14 | proc mixed data=sp4r.grass method=REML; 15 | class method variety; 16 | model yield = method / solution ddfm=kr2; 17 | random variety method*variety; 18 | lsmeans method / pdiff; 19 | estimate 'A vs. B and C' method 1 -.5 -.5; 20 | run; 21 | 22 | /*Part C*/ 23 | ods select type3; 24 | proc mixed data=sp4r.grass method=type3; 25 | class method variety; 26 | model yield = method / solution ddfm=kr2; 27 | random variety method*variety; 28 | lsmeans method / pdiff; 29 | estimate 'A vs. B and C' method 1 -.5 -.5; 30 | run; 31 | -------------------------------------------------------------------------------- /code/SP4R06s01.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06s01*/ 7 | 8 | /*Part A*/ 9 | proc corr data=sp4r.bodyfat; 10 | var height neck chest weight; 11 | run; 12 | 13 | /*Part B*/ 14 | ods select basicmeasures; 15 | proc univariate data=sp4r.bodyfat; 16 | var height neck chest weight; 17 | run; 18 | 19 | /*Part C*/ 20 | proc sgscatter data=sp4r.bodyfat; 21 | plot weight * (height neck chest) / reg; 22 | run; 23 | 24 | /*Part D*/ 25 | ods select anova fitstatistics parameterestimates; 26 | proc reg data=sp4r.bodyfat; 27 | model weight = height neck chest; 28 | output out=sp4r.out predicted=pred residual=res; 29 | run;quit; 30 | 31 | /*Part E*/ 32 | ods select histogram qqplot; 33 | proc univariate data=sp4r.out; 34 | var res; 35 | histogram res / normal kernel; 36 | qqplot res / normal(mu=est sigma=est); 37 | run; 38 | 39 | 40 | -------------------------------------------------------------------------------- /code/SP4R06s02.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06s02*/ 7 | 8 | /*Part A*/ 9 | proc reg data=sp4r.bodyfat; 10 | model weight = height neck chest; 11 | store mymod; 12 | run;quit; 13 | 14 | /*Part B*/ 15 | proc plm restore=mymod; 16 | score data=sp4r.newdata_bodyfat_reg out=sp4r.pred_newdata_bodyfat predicted; 17 | run; 18 | 19 | /*Part C*/ 20 | proc print data=sp4r.pred_newdata_bodyfat; 21 | var weight height neck chest predicted; 22 | run; 23 | -------------------------------------------------------------------------------- /code/SP4R06s03.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06s03*/ 7 | 8 | /*Part A*/ 9 | proc freq data=sp4r.cars; 10 | table type; 11 | run; 12 | 13 | /*Part B*/ 14 | ods select moments histogram; 15 | proc univariate data=sp4r.cars; 16 | var mpg_highway; 17 | histogram mpg_highway / normal; 18 | run; 19 | 20 | /*Part C*/ 21 | proc glm data=sp4r.cars plots(only)=boxplot; 22 | class type (ref='Hybrid'); 23 | model mpg_highway = type / solution clparm; 24 | lsmeans type / adjust=tukey pdiff cl; 25 | estimate 'SUV vs Truck' type 1 0 0 -1 0 0; 26 | run;quit; 27 | 28 | -------------------------------------------------------------------------------- /code/SP4R06s04.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06s04*/ 7 | 8 | /*Part A*/ 9 | proc sql; 10 | select mean(horsepower) into :hp_mean from sp4r.cars; 11 | quit; 12 | 13 | /*Part B*/ 14 | proc glm data=sp4r.cars plots(only)=ancovaplot; 15 | class type (ref='Hybrid'); 16 | model mpg_highway = type|horsepower / solution clparm; 17 | lsmeans type / at horsepower=&hp_mean adjust=tukey pdiff cl; 18 | estimate 'SUV vs Truck' type 1 0 0 -1 0 0 type*horsepower 19 | &hp_mean 0 0 -&hp_mean 0 0; 20 | run;quit; 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /code/SP4R06s05.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06s05*/ 7 | 8 | /*Part A*/ 9 | proc freq data=sp4r.cars; 10 | tables type origin drivetrain; 11 | run; 12 | 13 | /*Part B*/ 14 | proc glmselect data=sp4r.cars outdesign=sp4r.des; 15 | class type origin drivetrain; 16 | model mpg_highway = type|origin|drivetrain / selection=forward 17 | select=sl sle=.05 hierarchy=single; 18 | run;quit; 19 | 20 | 21 | -------------------------------------------------------------------------------- /code/SP4R06s06.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06s06*/ 7 | 8 | /*Part A*/ 9 | proc corr data=sp4r.cars; 10 | var mpg_highway horsepower enginesize weight wheelbase length; 11 | run; 12 | 13 | /*Part B*/ 14 | proc glmselect data=sp4r.cars outdesign=sp4r.des; 15 | model mpg_highway = horsepower enginesize weight wheelbase length / 16 | selection=stepwise select=AICC; 17 | store mymod; 18 | run;quit; 19 | 20 | /*Part C*/ 21 | proc plm restore=mymod; 22 | score data=sp4r.newdata_cars out=sp4r.pred_newdata_cars 23 | predicted uclm lclm lcl ucl; 24 | run; 25 | 26 | /*Part D*/ 27 | proc print data=sp4r.pred_newdata_cars; 28 | var mpg_highway &_glsmod predicted uclm lclm lcl ucl; 29 | run; 30 | -------------------------------------------------------------------------------- /code/SP4R06s07.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06s07*/ 7 | 8 | /*Part A*/ 9 | proc print data=sp4r.cafeteria; 10 | run; 11 | 12 | /*Part B*/ 13 | proc sgplot data=sp4r.cafeteria; 14 | scatter x=dispensers y=sales; 15 | run; 16 | 17 | /*Part C*/ 18 | proc glmselect data=sp4r.cafeteria outdesign=sp4r.des plots=all; 19 | effect cafe_pol = polynomial(dispensers / degree=3); 20 | model sales = cafe_pol / selection=forward select=sl sle=.05 21 | hierarchy=single; 22 | run;quit; 23 | 24 | /*Part D*/ 25 | proc sgplot data=sp4r.cafeteria; 26 | reg x=dispensers y=sales / degree=2 legendlabel="Quadratic"; 27 | run; 28 | 29 | /*Part E*/ 30 | proc reg data=sp4r.des; 31 | model sales = &_glsmod; 32 | run;quit; 33 | -------------------------------------------------------------------------------- /code/SP4R06s08.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06s08*/ 7 | 8 | /*Part A*/ 9 | proc freq data=sp4r.safety; 10 | run; 11 | 12 | /*Part B*/ 13 | proc logistic data=sp4r.safety plots(only)=effect; 14 | class region(ref='Asia') size(ref='3') / param=ref; 15 | model unsafe(event='1') = weight region size / clodds=wald; 16 | estimate 'My Estimate' intercept 1 weight 4 region 1 size 1 0 / 17 | e alpha=.05 ilink; 18 | run; 19 | 20 | /*Part C*/ 21 | ods select modelbuildingsummary modelanova parameterestimates; 22 | proc logistic data=sp4r.safety; 23 | class region(ref='Asia') size(ref='3') / param=ref; 24 | model unsafe(event='1') = weight region size / 25 | selection=backward sls=.05 clodds=wald; 26 | run; 27 | 28 | -------------------------------------------------------------------------------- /code/SP4R06s09.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06s09*/ 7 | 8 | /*Part A*/ 9 | proc freq data=sp4r.earinfection; 10 | tables swimmer location age gender infections; 11 | run; 12 | 13 | /*Part B*/ 14 | ods select basicmeasures histogram; 15 | proc univariate data=sp4r.earinfection; 16 | var infections; 17 | histogram infections / normal; 18 | run; 19 | 20 | /*Part C*/ 21 | proc genmod data=sp4r.earinfection; 22 | class swimmer(ref='Occas') location(ref='NonBeach') 23 | gender(ref='Female') / param=ref; 24 | model infections = swimmer location age gender / 25 | dist=poisson type3; 26 | store mymod; 27 | run; 28 | 29 | /*Part D*/ 30 | data sp4r.newdata_inf; 31 | input Swimmer $ Location $ Age Gender $; 32 | datalines; 33 | Freq NonBeach 25 Female 34 | Occas Beach 15 Male 35 | ;run; 36 | 37 | /*Part E*/ 38 | proc plm restore=mymod; 39 | score data=sp4r.newdata_inf out=sp4r.scores / ilink; 40 | run; 41 | 42 | proc print data=sp4r.scores; 43 | run; 44 | -------------------------------------------------------------------------------- /code/SP4R06s10.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R06s10*/ 7 | 8 | /*Part A*/ 9 | proc sgplot data=sp4r.washer; 10 | vline store / group=brand stat=mean response=sales; 11 | run; 12 | 13 | /*Part B*/ 14 | 15 | /*Part C*/ 16 | 17 | /*Part D*/ 18 | proc mixed data=sp4r.washer method=reml; 19 | class brand store; 20 | model sales=brand / ddfm=kr2; 21 | random store brand*store; 22 | run; 23 | 24 | /*Part E*/ 25 | proc mixed data=sp4r.washer method=reml; 26 | class brand store; 27 | model sales=brand / ddfm=kr2; 28 | random store brand*store; 29 | estimate 'brand A vs brand B' brand 1 -1; 30 | run; 31 | 32 | /*Part F*/ 33 | proc mixed data=sp4r.washer method=type3; 34 | class brand store; 35 | model sales = brand; 36 | random store brand*store; 37 | estimate 'brand A vs B' brand 1 -1; 38 | run; 39 | 40 | -------------------------------------------------------------------------------- /code/SP4R07d01.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R07d01*/ 7 | 8 | /*Part A*/ 9 | proc iml; 10 | items ={'Groceries','Utilities','Rent','Car Expenses', 11 | 'Fun Money','Personal Expenses'}; 12 | weeks ={'Week 1','Week 2','Week 3','Week 4'}; 13 | amounts ={ 96 78 82 93, 14 | 61 77 62 68, 15 | 300 300 300 300, 16 | 25 27 98 18, 17 | 55 34 16 53, 18 | 110 85 96 118}; 19 | weeklyIncome={900 850 1050 950}; 20 | print items amounts weeklyIncome; 21 | print items, amounts, weeklyIncome; 22 | 23 | /*Part B*/ 24 | reset noname; 25 | weeklyTotals=amounts[+,]; 26 | print "Total Expenses for Each Week", weeklyTotals [colname=weeks format=dollar8.2]; 27 | 28 | /*Part C*/ 29 | itemTotals=amounts[,+]; 30 | print "Total Expenses for Each Item", itemTotals[rowname=items format=dollar8.2]; 31 | 32 | /*Part D*/ 33 | weeklyPercentage=amounts/weeklyIncome; 34 | print "Percentage of income spent on each item, by week", 35 | weeklyPercentage[rowname=items colname=weeks format=percent7.2]; 36 | 37 | /*Part E*/ 38 | monthlyIncome =weeklyIncome[+]; 39 | itemProportion =itemTotals/monthlyIncome; 40 | print "Each Item as a Percentage of Monthly Income", 41 | itemProportion[rowname=items format=percent7.2]; 42 | quit; 43 | -------------------------------------------------------------------------------- /code/SP4R07d02.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R07d02*/ 7 | 8 | /*Part A*/ 9 | proc iml; 10 | call randseed(27606); 11 | n = 20; 12 | beta0 = 5; 13 | beta1 = 2; 14 | 15 | xvals = j(n,1,0); 16 | call randgen(xvals,"Uniform"); 17 | xvals = xvals*20; 18 | 19 | error = j(n,1,0); 20 | call randgen(error,"Normal",0,5); 21 | 22 | y = beta0 + beta1*xvals + error; 23 | print y beta0 beta1 xvals error; 24 | 25 | /*Part B*/ 26 | x = j(n,1,1)||xvals; 27 | xpx = x`*x; 28 | print x, xpx; 29 | 30 | /*Part C*/ 31 | call svd(u,q,v,xpx); 32 | xpxSVD = u*diag(q)*v`; 33 | print u q v xpxSVD; 34 | 35 | /*Part D*/ 36 | qInv = 1/q; 37 | qInvDiag = diag(qInv); 38 | print q qInv qInvDiag; 39 | 40 | /*Part E*/ 41 | betaHat = (v*qInvDiag*u`)*(x`*y); 42 | print betaHat; 43 | quit; 44 | -------------------------------------------------------------------------------- /code/SP4R07d03.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R07d03*/ 7 | 8 | /*Part A*/ 9 | proc iml; 10 | start simpleRegFunc(xvals, yvals); 11 | n = nrow(xvals); 12 | x = j(n,1,1)||xvals; 13 | y = yvals; 14 | 15 | betaHat = inv(x`*x)*(x`*y); 16 | return(betaHat); 17 | finish; 18 | 19 | /*Part B*/ 20 | call randseed(27606); 21 | n = 20; 22 | beta0 = 5; 23 | beta1 = 2; 24 | xvals = randfun(n,"Uniform"); 25 | xvals = xvals*20; 26 | error = randfun(n,"Normal",0,5); 27 | y = beta0 + beta1*xvals + error; 28 | 29 | betas = simpleRegFunc(xvals,y); 30 | print betas; 31 | 32 | /*Part C*/ 33 | start simpleRegSub(betaHat, sigmaHat, xvals, yvals); 34 | n = nrow(xvals); 35 | x = j(n,1,1)||xvals; 36 | y = yvals; 37 | 38 | betaHat = inv(x`*x)*(x`*y); 39 | pred = x*betaHat; 40 | sse = sum( (y-pred)##2 ); 41 | sigma2Hat = sse / (n-1); 42 | sigmaHat = sqrt(sigma2Hat); 43 | finish; 44 | 45 | /*Part D*/ 46 | call simpleRegSub(betas,sHat,xvals,y); 47 | print betas sHat; 48 | 49 | /*Part E*/ 50 | reset storage=imlcat; 51 | store; 52 | show storage; 53 | quit; 54 | 55 | 56 | -------------------------------------------------------------------------------- /code/SP4R07d04.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R07d04*/ 7 | 8 | /*Part A*/ 9 | proc iml; 10 | use sp4r.cars; 11 | read all var {msrp mpg_city mpg_highway} where(msrp>80000) into imlCars; 12 | close sp4r.cars; 13 | 14 | varNames = {"MSRP" "MPG City" "MPG Highway"}; 15 | Means = mean(imlCars); 16 | print imlCars, Means[colname=varNames]; 17 | quit; 18 | 19 | /*Part B*/ 20 | proc iml; 21 | call randseed(802); 22 | n=10; 23 | weight = randfun(n,"Normal",200,50); 24 | age = randfun(n, "Poisson",35); 25 | 26 | create sp4r.newDataTable var{age weight}; 27 | append; 28 | close sp4r.newDataTable; 29 | 30 | /*Identical Result 2 31 | create sp4r.newDataTable2; 32 | append var{age weight}; 33 | close sp4r.newDataTable2;*/ 34 | 35 | /*Identical Result 3 36 | mymat = age||weight; 37 | print mymat; 38 | 39 | create newDataTable from mymat [colname={weight, age}]; 40 | append from mymat; 41 | close newDataTable;*/ 42 | quit; 43 | 44 | proc print data=sp4r.newDataTable; run; 45 | 46 | /*Part C*/ 47 | proc iml; 48 | call randseed(919); 49 | n=10; 50 | weight = randfun(n,"Normal",200,50); 51 | age = randfun(n, "Poisson",35); 52 | mymat = age||weight; 53 | 54 | edit sp4r.newDataTable; 55 | append from mymat; 56 | close sp4r.newDataTable; 57 | quit; 58 | 59 | proc print data=sp4r.newDataTable; run; 60 | -------------------------------------------------------------------------------- /code/SP4R07d05.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R07d05*/ 7 | 8 | /*Part A*/ 9 | proc iml; 10 | call randseed(27606); 11 | n = 20; 12 | beta0 = 5; 13 | beta1 = 2; 14 | xvals = randfun(n,"Uniform"); 15 | xvals = xvals*20; 16 | error = randfun(n,"Normal",0,5); 17 | y = beta0 + beta1*xvals + error; 18 | x = j(n,1,1)||xvals; 19 | betaHat = inv(x`*x)*(x`*y); 20 | print betaHat; 21 | 22 | /*Part B*/ 23 | create sp4r.betaData var{xvals y}; 24 | append; 25 | close sp4r.betaData; 26 | 27 | /*Part C*/ 28 | submit; 29 | ods select fitplot parameterestimates; 30 | proc reg data=sp4r.betaData; 31 | model y = xvals; 32 | run; 33 | endsubmit; 34 | quit; 35 | -------------------------------------------------------------------------------- /code/SP4R07d06.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R07d06*/ 7 | 8 | /*Part A*/ 9 | proc iml; 10 | numberIterations=10000; 11 | call randseed(802); 12 | 13 | /*Part B*/ 14 | do iteration=1 to numberIterations; 15 | doors = {1 2 3}; 16 | carDoor=sample(doors,1); 17 | 18 | /*Part C*/ 19 | *Pick door for Monty Hall to open; 20 | if carDoor=1 then openDoor=randfun(1,"Bernoulli",.5) + 2; 21 | else if carDoor=2 then openDoor=3; 22 | else if carDoor=3 then openDoor=2; 23 | 24 | /*Part D*/ 25 | *Determine door for switching strategy; 26 | if openDoor=2 then switchDoor=3; 27 | else if openDoor=3 then switchDoor=2; 28 | 29 | /*Part E*/ 30 | *Determine which strategy wins; 31 | if carDoor=1 then stayWin=1; 32 | else stayWin=0; 33 | 34 | if carDoor=switchDoor then switchWin=1; 35 | else switchWin=0; 36 | /*switchWin=carDoor=switchDoor;*/ 37 | 38 | /*Part F*/ 39 | *Collect results to a single matrix; 40 | results=results // (iteration || carDoor || openDoor || stayWin || switchWin); 41 | end; 42 | 43 | /*Part H*/ 44 | reset noname; 45 | resultsSubset = results[1:10,]; 46 | print resultsSubset [colname={iteration carDoor openDoor 47 | stayWin switchWin}]; 48 | 49 | percentageWins=results[:,{4 5}]; 50 | print percentageWins [colname={stay switch}]; 51 | quit; 52 | -------------------------------------------------------------------------------- /code/SP4R07d07.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R07d07*/ 7 | 8 | /*Part A*/ 9 | proc iml; 10 | start simpleRegFunc(n,beta0,beta1); 11 | xvals = randfun(n,"Uniform"); 12 | xvals = xvals*20; 13 | error = randfun(n,"Normal",0,5); 14 | y = beta0 + beta1*xvals + error; 15 | x = j(n,1,1)||xvals; 16 | betaHat = inv(x`*x)*(x`*y); 17 | return(betaHat); 18 | finish; 19 | 20 | /*Part B*/ 21 | n = 20; 22 | reps = 1000; 23 | beta0 = j(reps,1,.); 24 | beta1 = j(reps,1,.); 25 | call randseed(27606); 26 | 27 | /*Part C*/ 28 | do i=1 to reps; 29 | betas = simpleRegFunc(n,5,2); 30 | beta0[i] = betas[1]; 31 | beta1[i] = betas[2]; 32 | end; 33 | 34 | /*Part D*/ 35 | mean0 = mean(beta0); 36 | sd0 = std(beta0); 37 | call qntl(percentiles0,beta0,{.025, .975}); 38 | 39 | mean1 = mean(beta1); 40 | sd1 = std(beta1); 41 | call qntl(percentiles1,beta1,{.025, .975}); 42 | 43 | out0 = mean0//sd0//percentiles0; 44 | reset noname; 45 | print out0[colname="Beta0" rowname={"Mean","Standard Deviation","LCL","UCL"}]; 46 | 47 | out1 = mean1//sd1//percentiles1; 48 | print out1[colname="Beta1" rowname={"Mean","Standard Deviation","LCL","UCL"}]; 49 | quit; 50 | -------------------------------------------------------------------------------- /code/SP4R07d08.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R07d08*/ 7 | 8 | /*Part A*/ 9 | proc iml; 10 | start simpleRegSub(xvals,yvals,n); 11 | beta0 = 5; 12 | beta1 = 2; 13 | xvals = randfun(n,"Uniform"); 14 | xvals = xvals*20; 15 | error = randfun(n,"Normal",0,5); 16 | yvals = beta0 + beta1*xvals + error; 17 | finish; 18 | 19 | /*Part B*/ 20 | n = 20; 21 | reps = 1000; 22 | beta0 = j(reps,1,.); 23 | beta1 = j(reps,1,.); 24 | call randseed(27606); 25 | startTime = time(); 26 | 27 | /*Part C*/ 28 | do i=1 to reps; 29 | call simpleRegSub(x,y,n); 30 | 31 | create sp4r.simulation var {x y}; 32 | append; 33 | close sp4r.simulation; 34 | 35 | /*Part D*/ 36 | submit; 37 | ods select none; 38 | ods output ParameterEstimates=sp4r.params; 39 | proc reg data=sp4r.simulation; 40 | model y=x; 41 | run; 42 | ods select default; 43 | endsubmit; 44 | 45 | /*Part E*/ 46 | use sp4r.params; 47 | read all var {estimate} into estimates; 48 | close sp4r.params; 49 | 50 | beta0[i]=estimates[1]; 51 | beta1[i]=estimates[2]; 52 | end; 53 | 54 | /*Part F*/ 55 | mean0 = mean(beta0); 56 | sd0 = std(beta0); 57 | call qntl(percentiles0,beta0,{.025, .975}); 58 | 59 | mean1 = mean(beta1); 60 | sd1 = std(beta1); 61 | call qntl(percentiles1,beta1,{.025, .975}); 62 | 63 | out0 = mean0//sd0//percentiles0; 64 | reset noname; 65 | print out0[colname="Beta0" 66 | rowname={"Mean","Standard Deviation","LCL","UCL"}]; 67 | 68 | out1 = mean1//sd1//percentiles1; 69 | print out1[colname="Beta1" 70 | rowname={"Mean","Standard Deviation","LCL","UCL"}]; 71 | 72 | total = time() - startTime; 73 | print total[colname="Elapsed Time"]; 74 | quit; 75 | -------------------------------------------------------------------------------- /code/SP4R07d09.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R07d09*/ 7 | 8 | /*Part A*/ 9 | proc iml; 10 | startTime = time(); 11 | simulations = 1000; 12 | sampleSize = 20; 13 | 14 | /*Part B*/ 15 | simulationNumber = 1:simulations; 16 | each = j(simulations,1,sampleSize); 17 | simulationNumber = repeat(simulationNumber,each)`; 18 | 19 | /*Part C*/ 20 | call randseed(27606); 21 | total = simulations*sampleSize; 22 | beta0 = 5; 23 | beta1 = 2; 24 | xvals = randfun(total,"Uniform"); 25 | x = xvals*20; 26 | error = randfun(total,"Normal",0,5); 27 | y = beta0 + beta1*x + error; 28 | 29 | /*Part D*/ 30 | create sp4r.simulation var {simulationNumber x y}; 31 | append; 32 | close sp4r.simulation; 33 | 34 | /*Part E*/ 35 | submit; 36 | ods select none; 37 | ods output ParameterEstimates=sp4r.params; 38 | proc reg data=sp4r.simulation; 39 | by simulationNumber; 40 | model y=x; 41 | run; 42 | ods select default; 43 | endsubmit; 44 | 45 | /*Part F*/ 46 | use sp4r.params; 47 | read all var {estimate} where (variable='Intercept') into beta0; 48 | close sp4r.params; 49 | 50 | use sp4r.params; 51 | read all var {estimate} where (variable='X') into beta1; 52 | close sp4r.params; 53 | 54 | /*Part G*/ 55 | mean0 = mean(beta0); 56 | sd0 = std(beta0); 57 | call qntl(percentiles0,beta0,{.025, .975}); 58 | 59 | mean1 = mean(beta1); 60 | sd1 = std(beta1); 61 | call qntl(percentiles1,beta1,{.025, .975}); 62 | 63 | out0 = mean0//sd0//percentiles0; 64 | reset noname; 65 | print out0[colname="Beta0" 66 | rowname={"Mean","Standard Deviation","LCL","UCL"}]; 67 | 68 | out1 = mean1//sd1//percentiles1; 69 | print out1[colname="Beta1" 70 | rowname={"Mean","Standard Deviation","LCL","UCL"}]; 71 | 72 | total = time() - startTime; 73 | print total[colname="Elapsed Time"]; 74 | quit; 75 | -------------------------------------------------------------------------------- /code/SP4R07s01.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R07s01*/ 7 | 8 | proc iml; 9 | items ={'Groceries','Utilities','Rent','Car Expenses', 10 | 'Fun Money','Personal Expenses'}; 11 | weeks ={'Week 1','Week 2','Week 3','Week 4'}; 12 | amounts ={96 78 82 93, 13 | 61 77 62 68, 14 | 300 300 300 300, 15 | 25 27 98 18, 16 | 55 34 16 53, 17 | 110 85 96 118}; 18 | weeklyIncome ={900 850 1050 950}; 19 | weeklyExpenses=amounts[+,]; 20 | 21 | /*Part A*/ 22 | proportionIncomeSpent=weeklyExpenses / weeklyIncome; 23 | reset noname; 24 | print "Proportion of income spent each week", 25 | proportionIncomeSpent[colname=weeks format=percent7.2]; 26 | 27 | /*Part B*/ 28 | proportionIncomeSaved=1 - proportionIncomeSpent; 29 | print "Proportion of income saved each week", 30 | proportionIncomeSaved[colname=weeks format=percent7.2]; 31 | 32 | /*Part C*/ 33 | proportionSpentPerItem=amounts/weeklyIncome; 34 | print "Percentage of income spent on each item, by week", 35 | proportionSpentPerItem [rowname=items 36 | colname=weeks format=percent7.2]; 37 | 38 | /*Part D*/ 39 | weeklyExpenseChange={. . ., 40 | . . ., 41 | . . ., 42 | . . ., 43 | . . ., 44 | . . .}; 45 | 46 | weeklyExpenseChange [,1]=amounts[,2] - amounts[,1]; 47 | weeklyExpenseChange [,2]=amounts[,3] - amounts[,2]; 48 | weeklyExpenseChange [,3]=amounts[,4] - amounts[,3]; 49 | 50 | print "Change in spending from previous week, by item", 51 | weeklyExpenseChange [rowname=items 52 | colname={"Week 2","Week 3", "Week 4"}]; 53 | quit; 54 | -------------------------------------------------------------------------------- /code/SP4R07s02.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R07s02*/ 7 | 8 | /*Part A*/ 9 | proc iml; 10 | call randseed(27606); 11 | n = 20; 12 | beta0 = 3; 13 | beta1 = 2; 14 | beta2 = -1; 15 | xvals1 = randfun(n,"Uniform"); 16 | xvals1 = xvals1*20; 17 | xvals2 = randfun(n,"Uniform"); 18 | xvals2 = (xvals2*20) + 10; 19 | error = randfun(n,"Normal",0,5); 20 | y = beta0 + beta1*xvals1 + beta2*xvals2 + error; 21 | print y beta0 beta1 beta2 xvals1 xvals2 error; 22 | 23 | /*Part B*/ 24 | x = j(n,1,1)||xvals1||xvals2; 25 | betaHat = inv(x`*x)*(x`*y); 26 | print x, betaHat; 27 | *Alternative SAS Function; 28 | *betaHat = solve( (x`*x)*(x`*y) ); 29 | *print betaHat; 30 | 31 | /*Part C*/ 32 | pred = x*betaHat; 33 | sse = sum( (y-pred)##2 ); 34 | sigma2Hat = sse / (n-1); 35 | sigmaHat = sqrt(sigma2Hat); 36 | print sigma2Hat sigmaHat; 37 | quit; 38 | -------------------------------------------------------------------------------- /code/SP4R07s03.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R07s03*/ 7 | 8 | /*Part A*/ 9 | proc iml; 10 | start standardize(x); 11 | n=nrow(x); 12 | mean=x[:,]; /* means for all columns */ 13 | xbar=repeat(mean,n,1); /* n rows of means */ 14 | x=x-xbar; /* center x to mean zero */ 15 | stdv=std(x); /* standard deviations for columns */ 16 | x=x/stdv; /* scale to std dev 1 */ 17 | return(x); 18 | finish; 19 | 20 | /*Part B*/ 21 | n = 10; 22 | call randseed(802); 23 | mymat = randfun(n,"Normal",5,5) 24 | ||randfun(n,"Uniform",10,15)||randfun(n,"Exponential",7); 25 | print mymat; 26 | stand = standardize(mymat); 27 | print stand; 28 | quit; 29 | 30 | /*Part C*/ 31 | proc iml; 32 | start standsub(stand,mean,stdv,x); 33 | n=nrow(x); 34 | mean=x[:,]; /* means for all columns */ 35 | xbar=repeat(mean,n,1); /* n rows of means */ 36 | x=x-xbar; /* center x to mean zero */ 37 | stdv=std(x); /* standard deviations for columns */ 38 | stand=x/stdv; /* scale to std dev 1 */ 39 | finish; 40 | 41 | /*Part D*/ 42 | n = 10; 43 | call randseed(802); 44 | mymat = randfun(n,"Normal",5,5) 45 | ||randfun(n,"Uniform",10,15)||randfun(n,"Exponential",7); 46 | call standsub(standardized,m,s,mymat); 47 | print m, s, standardized; 48 | quit; 49 | -------------------------------------------------------------------------------- /code/SP4R07s04.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R07s04*/ 7 | 8 | /*Part A*/ 9 | proc print data=sp4r.govtdemand; 10 | run; 11 | 12 | /*Part B*/ 13 | proc iml; 14 | use sp4r.govtDemand; 15 | read all into govt; 16 | close sp4r.govtDemand; 17 | 18 | /*Part C*/ 19 | start impute(colvec); 20 | colvec[loc(colvec=.)] = mean(colvec); 21 | return(colvec); 22 | finish impute; 23 | 24 | /*Part D*/ 25 | govtImputed = govt[,1]||impute(govt[,2]) 26 | ||impute(govt[,3])||impute(govt[,4]); 27 | create sp4r.newGovt from govtImputed 28 | [colname={year, agric, manu, labor}]; 29 | append from govtImputed; 30 | close sp4r.newGovt; 31 | 32 | /*Part E*/ 33 | submit; 34 | proc print data=sp4r.newGovt;run; 35 | proc corr data=sp4r.newGovt; 36 | var agric manu labor; 37 | run; 38 | endsubmit; 39 | quit; 40 | -------------------------------------------------------------------------------- /code/SP4R07s05.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R07s05*/ 7 | 8 | /*Part A*/ 9 | proc iml; 10 | use sp4r.ameshousing; 11 | read all var {saleprice overall_qual gr_liv_area garage_area 12 | basement_area deck_porch_area age_sold} into imlAmes; 13 | close sp4r.ameshousing; 14 | 15 | /*Part B*/ 16 | corrAmes = corr(imlAmes); 17 | print corrAmes; 18 | 19 | /*Part C*/ 20 | varNames = {"Sale Price" "Overall Quality" "Ground Living Area" 21 | "Garage Area" "Basement Area" "Deck Porch Area" 22 | "Age Sold (years)" }; 23 | call heatmapcont(corrAmes) xvalues=varNames yvalues=varNames 24 | colorramp="Temperature" title="Heatmap for Ames Data"; 25 | quit; 26 | -------------------------------------------------------------------------------- /code/SP4R07s06.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R07s06*/ 7 | 8 | /*Part A*/ 9 | proc iml; 10 | n=23; 11 | numberIterations=1000; 12 | call randseed(802); 13 | pair = j(numberIterations,1,.); 14 | do iteration=1 to numberIterations; 15 | 16 | /*Part B*/ 17 | dates = 1:365; 18 | birthDates=sample(dates,n); 19 | 20 | /*Part C*/ 21 | uniqueDates=unique(birthDates); 22 | /*Part D*/ 23 | if ncol(uniqueDates) < n then pair[iteration]=1; 24 | else pair[iteration]=0; 25 | end; 26 | 27 | /*Part E*/ 28 | proportion=pair[:]; 29 | print proportion; 30 | quit; 31 | 32 | /*Part F*/ 33 | proc iml; 34 | n=23; 35 | numberIterations=1000; 36 | call randseed(23571113); 37 | prob=j(364,1,1/365); 38 | birthDates=j(numberIterations,n,.); 39 | call randgen(birthDates,"Table",prob); 40 | 41 | rowUnique=countunique(birthDates,"ROW"); 42 | proportion=(rowUnique < n)[+] / numberIterations; 43 | print proportion; 44 | quit; 45 | -------------------------------------------------------------------------------- /code/SP4R07s07.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R07s07*/ 7 | 8 | /*Part A*/ 9 | proc iml; 10 | start mySample(n,min,max); 11 | x = randfun(n,"Uniform",min,max); 12 | return(x); 13 | finish; 14 | 15 | /*Part B*/ 16 | n = 30; 17 | min = 5; 18 | max = 10; 19 | call randseed(802); 20 | reps = 1000; 21 | vec = j(reps,1,.); 22 | 23 | /*Part C*/ 24 | do i=1 to reps; 25 | vec[i] = mean(mySample(n,min,max)); 26 | end; 27 | 28 | /*Part D*/ 29 | create sp4r.simulation var {vec}; 30 | append; 31 | close sp4r.simulation; 32 | 33 | /*Part E*/ 34 | submit; 35 | ods select basicmeasures histogram; 36 | proc univariate data=sp4r.simulation; 37 | var vec; 38 | histogram vec; 39 | run; 40 | endsubmit; 41 | quit; 42 | -------------------------------------------------------------------------------- /code/SP4R07s08.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R07s08*/ 7 | 8 | /*Part A*/ 9 | proc iml; 10 | simulations = 1000; 11 | sampleSize = 30; 12 | min = 5; 13 | max = 10; 14 | call randseed(802); 15 | 16 | /*Part B*/ 17 | simulationNumber = 1:simulations; 18 | each = j(simulations,1,sampleSize); 19 | simulationNumber = repeat(simulationNumber,each)`; 20 | 21 | /*Part C*/ 22 | total = simulations*sampleSize; 23 | vec = randfun(total,"Uniform",min,max); 24 | 25 | /*Part D*/ 26 | create sp4r.simulation var {simulationNumber vec}; 27 | append; 28 | close sp4r.simulation; 29 | 30 | /*Part E*/ 31 | submit; 32 | ods select none; 33 | proc means data=sp4r.simulation; 34 | by simulationNumber; 35 | var vec; 36 | output out=sp4r.out mean=mean; 37 | run; 38 | ods select default; 39 | endsubmit; 40 | 41 | /*Part F*/ 42 | use sp4r.out; 43 | read all var {mean} into means; 44 | close sp4r.out; 45 | 46 | /*Part G*/ 47 | mean = mean(means); 48 | sd = std(means); 49 | call qntl(percentiles,means,{.025, .975}); 50 | 51 | out = mean//sd//percentiles; 52 | reset noname; 53 | print out[colname="Mu" 54 | rowname={"Mean","Standard Deviation","LCL","UCL"}]; 55 | quit; 56 | -------------------------------------------------------------------------------- /code/SP4R08d01.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R08d01*/ 7 | 8 | /*Part A*/ 9 | ods select basicmeasures histogram; 10 | proc univariate data=sp4r.fish; 11 | var weight; 12 | histogram weight; 13 | run; 14 | 15 | /*Part B 16 | proc iml; 17 | submit / r; 18 | install.packages("boot") 19 | endsubmit; 20 | quit;*/ 21 | 22 | /* 23 | NOTE: You must delete the SAS comments in the SUBMIT block. 24 | The comments are passed to R and cause errors! 25 | */ 26 | /*Part C*/ 27 | proc iml; 28 | call ExportDataSetToR("sp4r.fish","fish"); 29 | 30 | /*Part D*/ 31 | submit / r; 32 | library(boot) 33 | set.seed(802) 34 | numreps = 1000 35 | 36 | bootMean <- function(data,variable,index){ 37 | attach(data) 38 | result <- mean(variable[index],na.rm=TRUE) 39 | detach(data) 40 | return(result) 41 | } 42 | 43 | results <- boot(data=fish,statistic=bootMean, 44 | R=numreps,variable=Weight) 45 | 46 | /*Part E*/ 47 | boot.ci(results, conf=0.95, type="perc", index=1) 48 | plot(results) 49 | 50 | /*Part F*/ 51 | boots <- data.frame("boots"=results$t) 52 | endsubmit; 53 | 54 | /*Part G*/ 55 | call ImportDataSetFromR("sp4r.RData","boots"); 56 | 57 | submit; 58 | proc print data=sp4r.RData (obs=10); 59 | run; 60 | endsubmit; 61 | quit; 62 | -------------------------------------------------------------------------------- /code/SP4R08s01.sas: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------*/ 2 | /* SAS Programming for R Users - code for exercises */ 3 | /* Copyright 2016 SAS Institute Inc. */ 4 | /*--------------------------------------------------*/ 5 | 6 | /*SP4R08s01*/ 7 | 8 | /*Part A*/ 9 | proc iml; 10 | call ExportDataSetToR("sp4r.fish","fish"); 11 | 12 | /*Part B*/ 13 | submit / r; 14 | fit <- lm(Weight ~ Height + Width, data=fish) 15 | summary(fit) 16 | endsubmit; 17 | 18 | /*Part C*/ 19 | call ImportMatrixFromR(r_Coefficients,"fit$coefficients"); 20 | /*Part D*/ 21 | submit; 22 | ods select none; 23 | proc reg data=sp4r.fish outest=sp4r.betas; 24 | model weight = height width; 25 | run;quit; 26 | ods select default; 27 | endsubmit; 28 | 29 | /*Part E*/ 30 | use sp4r.betas; 31 | read all var {intercept height width} into sas_Coefficients; 32 | close sp4r.betas; 33 | 34 | /*Part F*/ 35 | coefficients = sas_coefficients` || r_coefficients || 36 | (sas_coefficients` - r_coefficients); 37 | 38 | reset noname; 39 | coefficientNames = {SAS_Coefficients R_Coefficients Difference}; 40 | print coefficients[colname=coefficientNames]; 41 | quit; 42 | -------------------------------------------------------------------------------- /data/allnames.csv: -------------------------------------------------------------------------------- 1 | Jordan,Bakerman,27,68 2 | Bruce,Wayne,35,70 3 | Walter,White,51,70 4 | Henry,Hill,65,66 5 | JeanClaude,VanDamme,55,69 6 | Damion,Goodenow,33,81 7 | Shannan,Moehrle,41,74 8 | Zena,Seigfried,17,77 9 | Cheree,Waldschmidt,41,77 10 | Steffanie,Sadeghi,55,71 11 | Reid,Hieserich,46,74 12 | Lora,Bogdanovich,5,67 13 | Arnoldo,Hacher,24,83 14 | Harriette,People,25,74 15 | Ivelisse,Rawles,35,70 16 | Ami,Moland,36,76 17 | Elisa,Osbon,46,76 18 | Jesusa,Westerheide,31,69 19 | Jerlene,Prosienski,37,68 20 | Yolande,Brunderman,19,71 21 | Janene,Thyne,15,76 22 | Esteban,Ciucci,51,79 23 | Veda,Felipa,46,75 24 | Charlie,Gangwish,48,68 25 | Angelo,Greenweig,21,72 26 | Claudio,Vitolo,50,76 27 | Edgardo,Braulio,22,74 28 | Earnest,Jozwick,32,76 29 | Sammie,Lefchik,22,68 30 | Precious,Laffitte,44,67 31 | Marleen,Markarian,29,70 32 | Camellia,Detherage,24,71 33 | Elda,Rudnicki,33,70 34 | Patrick,Jaussi,17,70 35 | Kate,Eylicio,51,75 36 | Chanel,Leard,40,67 37 | Debora,Rebolloso,37,71 38 | Contessa,Fijalkowski,24,78 39 | Mandy,Lofredo,38,64 40 | Bo,Gailliard,39,70 41 | Denis,Greenblatt,48,75 42 | Chris,Arambuia,34,75 43 | Krista,Sagendorf,41,66 44 | Jacquline,Schutt,38,76 45 | Julieta,Pion,44,68 46 | Ivan,Zuberbuhler,47,77 47 | Rea,Garter,27,72 48 | Trinidad,Armstong,40,76 49 | Roxanna,Karatz,18,68 50 | Savanna,Uccio,27,69 51 | Lauralee,Southwell,12,78 52 | Felix,Midgley,23,66 53 | Treasa,Nikolas,33,73 54 | Aleen,Bierman,55,71 55 | Armanda,Olivarra,34,71 56 | Zona,Kiefel,35,69 57 | Dede,Swanteck,41,70 58 | Patrina,Ryer,23,77 59 | Valentine,Firpi,34,65 60 | Bee,Bevilaqua,29,70 61 | Darin,Traverse,21,71 62 | Rima,Daber,39,70 63 | Cherryl,Marthaler,52,76 64 | Alysia,Rochel,27,77 65 | Romona,Harnar,29,79 66 | Corrie,Pedregon,46,69 67 | Wilda,Haubrick,12,77 68 | Ok,Lathern,45,78 69 | Iola,Mcomber,38,67 70 | Wes,Abrial,38,68 71 | Leonor,Revord,26,65 72 | Clarissa,Lopez,46,66 73 | Shanelle,Barbati,33,74 74 | Augusta,Broom,22,74 75 | Lucius,Tande,37,77 76 | Woodrow,Fowlie,31,68 77 | Dorian,Creggett,24,72 78 | Richelle,Nocar,42,71 79 | Tyree,Dumdei,46,70 80 | Arianna,Manhart,33,72 81 | Juliane,Glazier,32,68 82 | Christa,Brochard,41,73 83 | Carlie,Scoma,32,77 84 | Karin,Lampley,22,67 85 | Refugio,Grossenbacher,40,73 86 | Shemika,Hardemon,38,78 87 | Adrianna,Maylone,29,71 88 | Anya,Marichalar,31,76 89 | Brain,Harns,26,70 90 | Cyrus,Sanlucas,29,69 91 | Joanie,Salabarria,30,82 92 | Garry,Fjeld,37,65 93 | Theodora,Rackow,41,70 94 | Brooks,Loftus,33,78 95 | Suellen,Avancena,36,78 96 | Juliet,Jaarda,51,69 97 | Mickey,Bashir,37,72 98 | Seema,Haaf,41,71 99 | Gracia,Brentley,35,69 100 | Elaine,Kniceley,41,68 101 | Melynda,Deniz,32,71 102 | Wilfred,Poling,45,69 103 | Millard,Harlin,22,74 104 | Christena,Roguemore,41,65 105 | Cinda,Simonetti,40,70 106 | Tod,Carlstrom,34,67 107 | Connie,Sokoloski,23,68 108 | Fay,Tierce,36,73 109 | Julie,Reinhard,42,71 110 | Robert,Indeck,24,77 111 | Gearldine,Lebrecque,41,71 112 | Alexander,Cocco,53,72 113 | Shirleen,Duren,28,70 114 | Freddy,Endecott,45,71 115 | Gidget,Buttray,26,72 116 | Myung,Deojay,45,79 117 | Eduardo,Brezinka,36,73 118 | Chan,Rohal,43,73 119 | Chrissy,Coggeshall,51,68 120 | Arline,Pavella,30,77 121 | Lashawn,Cottongim,66,76 122 | Britteny,Fullerton,40,73 123 | Doretta,Buchna,32,75 124 | Arturo,Lasley,44,84 125 | Johnette,Grosjean,41,72 126 | Bethany,Senger,40,67 127 | Ellan,Motte,18,75 128 | Ivette,Kiniry,26,67 129 | Jalisa,Grinman,41,65 130 | Lorri,Menjiva,33,57 131 | Elna,Sorin,40,75 132 | Ava,Felks,51,67 133 | Pa,August,52,76 134 | Fermina,Babula,34,73 135 | Shamika,Fondaw,39,69 136 | Jana,Schrandt,27,66 137 | Antoinette,Rouly,26,71 138 | Magdalena,Buchberger,50,75 139 | Niki,Widrig,24,72 140 | Mechelle,Thaden,47,73 141 | Carmela,Buikema,36,74 142 | Winnie,Saur,42,69 143 | Raymonde,Linan,44,70 144 | Lourdes,Noerenberg,47,69 145 | Hannelore,Mallozzi,27,76 146 | Kiana,Cherven,31,66 147 | Ashlee,Mbamalu,39,74 148 | Jim,Cessor,46,81 149 | Olivia,Esposita,31,77 150 | Else,Poque,39,69 151 | Evon,Repenning,24,67 152 | Curt,Topel,27,74 153 | Christene,Docken,27,70 154 | Yajaira,Espinosa,48,74 155 | Carrie,Nissila,40,63 156 | Annalee,Wiemer,33,70 157 | Deneen,Trybala,53,67 158 | Manuel,Shoultz,25,67 159 | Rubi,Knaust,34,73 160 | Nickie,Honzell,46,61 161 | Jerrold,Antill,33,79 162 | Lamont,Scheve,34,75 163 | Numbers,Durk,38,75 164 | Santa,Dobberstein,19,71 165 | Ona,Stayter,40,68 166 | Nedra,Tietze,24,78 167 | Tanja,Guzon,36,77 168 | Ermelinda,Dirkson,32,70 169 | Frances,Shortell,30,72 170 | Racheal,Frisbie,24,82 171 | Alita,Veres,28,70 172 | Ora,Teltschik,22,76 173 | Henriette,Riska,32,75 174 | Luke,Boyack,40,68 175 | Gayla,Buntrock,39,65 176 | Bridgett,Susich,20,65 177 | Amparo,Brouillard,42,67 178 | Rod,Hogenmiller,44,72 179 | Ivonne,Cyrus,48,68 180 | Kelley,Bellflowers,42,62 181 | Melodee,Loatman,28,73 182 | Herschel,Raynolds,35,63 183 | Breanne,Senneker,37,75 184 | Tosha,Lafortune,35,65 185 | Theresia,Fetui,52,65 186 | Shiela,Bialik,42,72 187 | Pete,Mages,49,73 188 | Stasia,Crockett,50,80 189 | Ray,Whittle,54,84 190 | Virgil,Baldenegro,45,70 191 | Camie,Westveer,43,72 192 | Sheila,Kuhlo,46,78 193 | Julian,Minchey,20,77 194 | Nina,Fiorenzi,27,71 195 | Deshawn,Poulter,46,73 196 | Maybelle,Marrs,35,62 197 | Josephina,Trumbo,23,66 198 | Ester,Degraw,40,67 199 | Argentina,Akahi,28,70 200 | Phyllis,Vafiadis,34,70 201 | -------------------------------------------------------------------------------- /data/amesbyyear.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/sas-prog-for-r-users/d68fee4f3276c8828bba7488b10103cb71285984/data/amesbyyear.xlsx -------------------------------------------------------------------------------- /data/baseball.csv: -------------------------------------------------------------------------------- 1 | Name,Team,nAtBat,nHits,nHome,nRuns,nRBI,League,Division,Position,nError 2 | "Allanson, Andy",Cleveland,293,66,1,30,29,American,East,C,20 3 | "Ashby, Alan",Houston,315,81,7,24,38,National,West,C,10 4 | "Davis, Alan",Seattle,479,130,18,66,72,American,West,1B,14 5 | "Dawson, Andre",Montreal,496,141,20,65,78,National,East,RF,3 6 | "Galarraga, Andres",Montreal,321,87,10,39,42,National,East,1B,4 7 | "Griffin, Alfredo",Oakland,594,169,4,74,51,American,West,SS,25 8 | "Newman, Al",Montreal,185,37,1,23,8,National,East,2B,7 9 | "Salazar, Argenis",Kansas City,298,73,0,24,24,American,West,SS,9 10 | "Thomas, Andres",Atlanta,323,81,6,26,32,National,West,SS,19 11 | "Thornton, Andre",Cleveland,401,92,17,49,66,American,East,DH,0 12 | "Trammell, Alan",Detroit,574,159,21,107,75,American,East,SS,22 13 | "Trevino, Alex",Los Angeles,202,53,4,31,26,National,West,C,11 14 | "Van Slyke, Andy",St Louis,418,113,13,48,61,National,East,RF,7 15 | "Wiggins, Alan",Baltimore,239,60,0,30,11,American,East,2B,6 16 | "Almon, Bill",Pittsburgh,196,43,7,29,27,National,East,UT,8 17 | "Beane, Billy",Minneapolis,183,39,3,20,15,American,West,OF,0 18 | "Bell, Buddy",Cincinnati,568,158,20,89,75,National,West,3B,10 19 | "Biancalana, Buddy",Kansas City,190,46,2,24,8,American,West,SS,16 20 | "Bochte, Bruce",Oakland,407,104,6,57,43,American,West,1B,9 21 | "Bochy, Bruce",San Diego,127,32,8,16,22,National,West,C,2 22 | "Bonds, Barry",Pittsburgh,413,92,16,72,48,National,East,CF,5 23 | "Bonilla, Bobby",Chicago,426,109,3,55,43,American,West,O1,2 24 | "Boone, Bob",California,442,98,7,48,49,American,West,C,11 25 | "Brenly, Bob",San Francisco,472,116,16,60,62,National,West,C,3 26 | "Buckner, Bill",Boston,629,168,18,73,102,American,East,1B,14 27 | "Butler, Brett",Cleveland,587,163,4,92,51,American,East,CF,3 28 | "Dernier, Bob",Chicago,324,73,4,32,18,National,East,CF,3 29 | "Diaz, Bo",Cincinnati,474,129,10,50,56,National,West,C,13 30 | "Doran, Bill",Houston,550,152,6,92,37,National,West,2B,16 31 | "Downing, Brian",California,513,137,20,90,95,American,West,LF,3 32 | "Grich, Bobby",California,313,84,9,42,30,American,West,2B,7 33 | "Hatcher, Billy",Houston,419,108,6,55,36,National,West,CF,4 34 | "Horner, Bob",Atlanta,517,141,27,70,87,National,West,1B,8 35 | "Jacoby, Brook",Cleveland,583,168,17,83,80,American,East,3B,25 36 | "Kearney, Bob",Seattle,204,49,6,23,25,American,West,C,5 37 | "Madlock, Bill",Los Angeles,379,106,10,38,60,National,West,3B,24 38 | "Meacham, Bobby",New York,161,36,0,19,10,American,East,SS,12 39 | "Melvin, Bob",San Francisco,268,60,5,24,25,National,West,C,6 40 | "Oglivie, Ben",Milwaukee,346,98,5,31,53,American,East,DH,0 41 | "Roberts, Bip",San Diego,241,61,1,34,12,National,West,2B,10 42 | "Robidoux, Billy Jo",Milwaukee,181,41,1,15,21,American,East,1B,5 43 | "Russell, Bill",Los Angeles,216,54,0,21,18,National,West,UT,5 44 | "Sample, Billy",Atlanta,200,57,6,23,14,National,West,OF,1 45 | "Schroeder, Bill",Milwaukee,217,46,7,32,19,American,East,UT,1 46 | "Wynegar, Butch",New York,194,40,7,19,29,American,East,C,2 47 | "Bando, Chris",Cleveland,254,68,2,28,26,American,East,C,4 48 | "Brown, Chris",San Francisco,416,132,7,57,49,National,West,3B,18 49 | "Castillo, Carmen",Cleveland,205,57,8,34,32,American,East,OD,4 50 | "Cooper, Cecil",Milwaukee,542,140,12,46,75,American,East,1B,9 51 | "Davis, Chili",San Francisco,526,146,13,71,70,National,West,RF,9 52 | "Fisk, Carlton",Chicago,457,101,14,42,63,American,West,C,4 53 | "Ford, Curt",St Louis,214,53,2,30,29,National,East,OF,3 54 | "Johnson, Cliff",Toronto,336,84,15,48,55,American,East,DH,0 55 | "Lansford, Carney",Oakland,591,168,19,80,72,American,West,3B,4 56 | "Lemon, Chet",Detroit,403,101,12,45,53,American,East,CF,5 57 | "Maldonado, Candy",San Francisco,405,102,18,49,85,National,West,OF,3 58 | "Martinez, Carmelo",San Diego,244,58,9,28,25,National,West,O1,2 59 | "Moore, Charlie",Milwaukee,235,61,3,24,39,American,East,C,4 60 | "Reynolds, Craig",Houston,313,78,6,32,41,National,West,SS,7 61 | "Ripken, Cal",Baltimore,627,177,25,98,81,American,East,SS,13 62 | "Snyder, Cory",Cleveland,416,113,24,58,69,American,East,OS,10 63 | "Speier, Chris",Chicago,155,44,6,21,23,National,East,3S,3 64 | "Wilkerson, Curt",Texas,236,56,0,27,15,American,West,2S,13 65 | "Anderson, Dave",Los Angeles,216,53,1,31,15,National,West,3S,11 66 | "Baker, Dusty",Oakland,242,58,4,25,19,American,West,OF,0 67 | "Baylor, Don",Boston,585,139,31,93,94,American,East,DH,0 68 | "Bilardello, Dann",Montreal,191,37,4,12,17,National,East,C,8 69 | "Boston, Daryl",Chicago,199,53,5,29,22,American,West,CF,5 70 | "Coles, Darnell",Detroit,521,142,20,67,86,American,East,3B,23 71 | "Collins, Dave",Detroit,419,113,1,44,27,American,East,LF,1 72 | "Concepcion, Dave",Cincinnati,311,81,3,42,30,National,West,UT,10 73 | "Daulton, Darren",Philadelphia,138,31,8,18,21,National,East,C,4 74 | "DeCinces, Doug",California,512,131,26,69,96,American,West,3B,12 75 | "Evans, Darrell",Detroit,507,122,29,78,85,American,East,1B,2 76 | "Evans, Dwight",Boston,529,137,26,86,97,American,East,RF,5 77 | "Garcia, Damaso",Toronto,424,119,6,57,46,American,East,2B,8 78 | "Gladden, Dan",San Francisco,351,97,4,55,29,National,West,CF,3 79 | "Heep, Danny",New York,195,55,5,24,33,National,East,OF,1 80 | "Henderson, Dave",Seattle,388,103,15,59,47,American,West,OF,4 81 | "Hill, Donnie",Oakland,339,96,4,37,29,American,West,23,9 82 | "Kingman, Dave",Oakland,561,118,35,70,94,American,West,DH,8 83 | "Lopes, Davey",Chicago,255,70,7,49,35,National,East,3O,8 84 | "Mattingly, Don",New York,677,238,31,117,113,American,East,1B,6 85 | "Motley, Darryl",Kansas City,227,46,7,23,20,American,West,RF,2 86 | "Murphy, Dale",Atlanta,614,163,29,89,83,National,West,CF,6 87 | "Murphy, Dwayne",Oakland,329,83,9,50,39,American,West,CF,2 88 | "Parker, Dave",Cincinnati,637,174,31,89,116,National,West,RF,9 89 | "Pasqua, Dan",New York,280,82,16,44,45,American,East,LF,2 90 | "Porter, Darrell",Texas,155,41,12,21,29,American,West,CD,1 91 | "Schofield, Dick",California,458,114,13,67,57,American,West,SS,18 92 | "Slaught, Don",Texas,314,83,13,39,46,American,West,C,4 93 | "Strawberry, Darryl",New York,475,123,27,76,93,National,East,RF,6 94 | "Sveum, Dale",Milwaukee,317,78,7,35,35,American,East,3B,26 95 | "Tartabull, Danny",Seattle,511,138,25,76,96,American,West,RF,8 96 | "Thon, Dickie",Houston,278,69,3,24,21,National,West,SS,10 97 | "Walling, Denny",Houston,382,119,13,54,58,National,West,3B,9 98 | "Winfield, Dave",New York,565,148,24,90,104,American,East,RF,5 99 | "Cabell, Enos",Los Angeles,277,71,2,27,29,National,West,1B,5 100 | "Davis, Eric",Cincinnati,415,115,27,97,71,National,West,LF,7 101 | "Milner, Eddie",Cincinnati,424,110,15,70,47,National,West,CF,3 102 | "Murray, Eddie",Baltimore,495,151,17,61,84,American,East,1B,13 103 | "Riles, Ernest",Milwaukee,524,132,9,69,47,American,East,SS,20 104 | "Romero, Ed",Boston,233,49,2,41,23,American,East,SS,10 105 | "Whitt, Ernie",Toronto,395,106,16,48,56,American,East,C,7 106 | "Lynn, Fred",Baltimore,397,114,23,67,67,American,East,CF,4 107 | "Rayford, Floyd",Baltimore,210,37,8,15,19,American,East,3B,15 108 | "Stubbs, Franklin",Los Angeles,420,95,23,55,58,National,West,LF,7 109 | "White, Frank",Kansas City,566,154,22,76,84,American,West,2B,10 110 | "Bell, George",Toronto,641,198,31,101,108,American,East,LF,10 111 | "Braggs, Glenn",Milwaukee,215,51,4,19,18,American,East,LF,12 112 | "Brett, George",Kansas City,441,128,16,70,73,American,West,3B,16 113 | "Brock, Greg",Los Angeles,325,76,16,33,52,National,West,1B,3 114 | "Carter, Gary",New York,490,125,24,81,105,National,East,C,8 115 | "Davis, Glenn",Houston,574,152,31,91,101,National,West,1B,11 116 | "Foster, George",New York,284,64,14,30,42,National,East,LF,4 117 | "Gaetti, Gary",Minneapolis,596,171,34,91,108,American,West,3B,21 118 | "Gagne, Greg",Minneapolis,472,118,12,63,54,American,West,SS,26 119 | "Hendrick, George",California,283,77,14,45,47,American,West,OF,5 120 | "Hubbard, Glenn",Atlanta,408,94,4,42,36,National,West,2B,19 121 | "Iorg, Garth",Toronto,327,85,3,30,44,American,East,32,12 122 | "Matthews, Gary",Chicago,370,96,21,49,46,National,East,LF,9 123 | "Nettles, Graig",San Diego,354,77,16,36,55,National,West,3B,16 124 | "Pettis, Gary",California,539,139,5,93,58,American,West,CF,7 125 | "Redus, Gary",Philadelphia,340,84,11,62,33,National,East,LF,4 126 | "Templeton, Garry",San Diego,510,126,2,42,44,National,West,SS,20 127 | "Thomas, Gorman",Seattle,315,59,16,45,36,American,West,DH,0 128 | "Walker, Greg",Chicago,282,78,13,37,51,American,West,1B,5 129 | "Ward, Gary",Texas,380,120,5,54,51,American,West,LF,1 130 | "Wilson, Glenn",Philadelphia,584,158,15,70,84,National,East,RF,4 131 | "Baines, Harold",Chicago,570,169,21,72,88,American,West,RF,5 132 | "Brooks, Hubie",Montreal,306,104,14,50,58,National,East,SS,15 133 | "Johnson, Howard",New York,220,54,10,30,39,National,East,3S,20 134 | "McRae, Hal",Kansas City,278,70,7,22,37,American,West,DH,0 135 | "Reynolds, Harold",Seattle,445,99,1,46,24,American,West,2B,16 136 | "Spilman, Harry",San Francisco,143,39,5,18,30,National,West,1B,1 137 | "Winningham, Herm",Montreal,185,40,4,23,11,National,East,OF,2 138 | "Barfield, Jesse",Toronto,589,170,40,107,108,American,East,RF,3 139 | "Beniquez, Juan",Baltimore,343,103,6,48,36,American,East,UT,13 140 | "Bonilla, Juan",Baltimore,284,69,1,33,18,American,East,2B,5 141 | "Cangelosi, John",Chicago,438,103,2,65,32,American,West,LF,9 142 | "Canseco, Jose",Oakland,600,144,33,85,117,American,West,LF,14 143 | "Carter, Joe",Cleveland,663,200,29,108,121,American,East,RF,6 144 | "Clark, Jack",St Louis,232,55,9,34,23,National,East,1B,3 145 | "Cruz, Jose",Houston,479,133,10,48,72,National,West,LF,4 146 | "Cruz, Julio",Chicago,209,45,0,38,19,American,West,2B,5 147 | "Davis, Jody",Chicago,528,132,21,61,74,National,East,C,8 148 | "Dwyer, Jim",Baltimore,160,39,8,18,31,American,East,DO,0 149 | "Franco, Julio",Cleveland,599,183,10,80,74,American,East,SS,18 150 | "Gantner, Jim",Milwaukee,497,136,7,58,38,American,East,2B,10 151 | "Grubb, Johnny",Detroit,210,70,13,32,51,American,East,DH,0 152 | "Hairston, Jerry",Chicago,225,61,5,32,26,American,West,UT,0 153 | "Howell, Jack",California,151,41,4,26,21,American,West,3B,2 154 | "Kruk, John",San Diego,278,86,4,33,38,National,West,LF,2 155 | "Leonard, Jeffrey",San Francisco,341,95,6,48,42,National,West,LF,5 156 | "Morrison, Jim",Pittsburgh,537,147,23,58,88,National,East,3B,20 157 | "Moses, John",Seattle,399,102,3,56,34,American,West,CF,3 158 | "Mumphrey, Jerry",Chicago,309,94,5,37,32,National,East,OF,3 159 | "Orsulak, Joe",Pittsburgh,401,100,2,60,19,National,East,RF,4 160 | "Orta, Jorge",Kansas City,336,93,9,35,46,American,West,DH,0 161 | "Presley, Jim",Seattle,616,163,27,83,107,American,West,3B,15 162 | "Quirk, Jamie",Kansas City,219,47,8,24,26,American,West,CS,4 163 | "Ray, Johnny",Pittsburgh,579,174,7,67,78,National,East,2B,5 164 | "Reed, Jeff",Minneapolis,165,39,2,13,9,American,West,C,2 165 | "Rice, Jim",Boston,618,200,20,98,110,American,East,LF,8 166 | "Royster, Jerry",San Diego,257,66,5,31,26,National,West,UT,14 167 | "Russell, John",Philadelphia,315,76,13,35,60,National,East,C,13 168 | "Samuel, Juan",Philadelphia,591,157,16,90,78,National,East,2B,25 169 | "Shelby, John",Baltimore,404,92,11,54,49,American,East,OF,5 170 | "Skinner, Joel",Chicago,315,73,5,23,37,American,West,C,3 171 | "Stone, Jeff",Philadelphia,249,69,6,32,19,National,East,OF,2 172 | "Sundberg, Jim",Kansas City,429,91,12,41,42,American,West,C,4 173 | "Traber, Jim",Baltimore,212,54,13,28,44,American,East,UT,5 174 | "Uribe, Jose",San Francisco,453,101,3,46,43,National,West,SS,16 175 | "Willard, Jerry",Oakland,161,43,4,17,26,American,West,C,2 176 | "Youngblood, Joel",San Francisco,184,47,5,20,28,National,West,OF,0 177 | "Bass, Kevin",Houston,591,184,20,83,79,National,West,RF,5 178 | "Daniels, Kal",Cincinnati,181,58,6,34,23,National,West,OF,3 179 | "Gibson, Kirk",Detroit,441,118,28,84,86,American,East,RF,2 180 | "Griffey, Ken",New York,490,150,21,69,58,American,East,OF,3 181 | "Hernandez, Keith",New York,551,171,13,94,83,National,East,1B,5 182 | "Hrbek, Kent",Minneapolis,550,147,29,85,91,American,West,1B,10 183 | "Landreaux, Ken",Los Angeles,283,74,4,34,29,National,West,OF,7 184 | "McReynolds, Kevin",San Diego,560,161,26,89,96,National,West,CF,8 185 | "Mitchell, Kevin",New York,328,91,12,51,43,National,East,OS,8 186 | "Moreland, Keith",Chicago,586,159,12,72,79,National,East,RF,4 187 | "Oberkfell, Ken",Atlanta,503,136,5,62,48,National,West,3B,8 188 | "Phelps, Ken",Seattle,344,85,24,69,64,American,West,DH,0 189 | "Puckett, Kirby",Minneapolis,680,223,31,119,96,American,West,CF,6 190 | "Stillwell, Kurt",Cincinnati,279,64,0,31,26,National,West,SS,16 191 | "Durham, Leon",Chicago,484,127,20,66,65,National,East,1B,7 192 | "Dykstra, Len",New York,431,127,8,77,45,National,East,CF,3 193 | "Herndon, Larry",Detroit,283,70,8,33,37,American,East,OF,2 194 | "Lacy, Lee",Baltimore,491,141,11,77,47,American,East,RF,2 195 | "Matuszek, Len",Los Angeles,199,52,9,26,28,National,West,O1,5 196 | "Moseby, Lloyd",Toronto,589,149,21,89,86,American,East,CF,6 197 | "Parrish, Lance",Detroit,327,84,22,53,62,American,East,C,6 198 | "Parrish, Larry",Texas,464,128,28,67,94,American,West,DH,0 199 | "Rivera, Luis",Montreal,166,34,0,20,13,National,East,SS,9 200 | "Sheets, Larry",Baltimore,338,92,18,42,60,American,East,DH,0 201 | "Smith, Lonnie",Kansas City,508,146,8,80,44,American,West,LF,9 202 | "Whitaker, Lou",Detroit,584,157,20,95,73,American,East,2B,11 203 | "Aldrete, Mike",San Francisco,216,54,2,27,25,National,West,1O,1 204 | "Barrett, Marty",Boston,625,179,4,94,60,American,East,2B,14 205 | "Brown, Mike",Pittsburgh,243,53,4,18,26,National,East,OF,3 206 | "Davis, Mike",Oakland,489,131,19,77,55,American,West,RF,9 207 | "Diaz, Mike",Pittsburgh,209,56,12,22,36,National,East,O1,3 208 | "Duncan, Mariano",Los Angeles,407,93,8,47,30,National,West,SS,25 209 | "Easler, Mike",New York,490,148,14,64,78,American,East,DH,0 210 | "Fitzgerald, Mike",Montreal,209,59,6,20,37,National,East,C,3 211 | "Hall, Mel",Cleveland,442,131,18,68,77,American,East,LF,7 212 | "Hatcher, Mickey",Minneapolis,317,88,3,40,32,American,West,UT,4 213 | "Heath, Mike",St Louis,288,65,8,30,36,National,East,C,10 214 | "Kingery, Mike",Kansas City,209,54,3,25,14,American,West,OF,3 215 | "LaValliere, Mike",St Louis,303,71,3,18,30,National,East,C,6 216 | "Marshall, Mike",Los Angeles,330,77,19,47,53,National,West,RF,6 217 | "Pagliarulo, Mike",New York,504,120,28,71,71,American,East,3B,19 218 | "Salas, Mark",Minneapolis,258,60,8,28,33,American,West,C,8 219 | "Schmidt, Mike",Philadelphia,552,160,37,97,119,National,East,3B,6 220 | "Scioscia, Mike",Los Angeles,374,94,5,36,26,National,West,C,15 221 | "Tettleton, Mickey",Oakland,211,43,10,26,35,American,West,C,8 222 | "Thompson, Milt",Philadelphia,299,75,6,38,23,National,East,CF,2 223 | "Webster, Mitch",Montreal,576,167,8,89,49,National,East,CF,8 224 | "Wilson, Mookie",New York,381,110,9,61,45,National,East,OF,5 225 | "Wynne, Marvell",San Diego,288,76,7,34,37,National,West,OF,3 226 | "Young, Mike",Baltimore,369,93,9,43,42,American,East,LF,6 227 | "Esasky, Nick",Cincinnati,330,76,12,35,41,National,West,1B,5 228 | "Guillen, Ozzie",Chicago,547,137,2,58,47,American,West,SS,22 229 | "McDowell, Oddibe",Texas,572,152,18,105,49,American,West,CF,3 230 | "Moreno, Omar",Atlanta,359,84,4,46,27,National,West,RF,5 231 | "Smith, Ozzie",St Louis,514,144,0,67,54,National,East,SS,15 232 | "Virgil, Ozzie",Atlanta,359,80,15,45,48,National,West,C,13 233 | "Bradley, Phil",Seattle,526,163,12,88,50,American,West,LF,1 234 | "Garner, Phil",Houston,313,83,9,43,41,National,West,3B,23 235 | "Incaviglia, Pete",Texas,540,135,30,82,88,American,West,RF,14 236 | "Molitor, Paul",Milwaukee,437,123,9,62,55,American,East,3B,15 237 | "O'Brien, Pete",Texas,551,160,23,86,90,American,West,1B,11 238 | "Rose, Pete",Cincinnati,237,52,0,15,25,National,West,1B,6 239 | "Sheridan, Pat",Detroit,236,56,6,41,19,American,East,OF,4 240 | "Tabler, Pat",Cleveland,473,154,6,61,48,American,East,1B,9 241 | "Belliard, Rafael",Pittsburgh,309,72,0,33,31,National,East,SS,12 242 | "Burleson, Rick",California,271,77,5,35,29,American,West,UT,3 243 | "Bush, Randy",Minneapolis,357,96,7,50,45,American,West,LF,4 244 | "Cerone, Rick",Milwaukee,216,56,4,22,18,American,East,C,4 245 | "Cey, Ron",Chicago,256,70,13,42,36,National,East,3B,8 246 | "Deer, Rob",Milwaukee,466,108,33,75,86,American,East,RF,8 247 | "Dempsey, Rick",Baltimore,327,68,13,42,29,American,East,C,7 248 | "Gedman, Rich",Boston,462,119,16,49,65,American,East,C,6 249 | "Hassey, Ron",New York,341,110,9,45,49,American,East,C,4 250 | "Henderson, Rickey",New York,608,160,28,130,74,American,East,CF,6 251 | "Jackson, Reggie",California,419,101,18,65,58,American,West,DH,0 252 | "Jones, Ruppert",California,393,90,17,73,49,American,West,RF,4 253 | "Kittle, Ron",Chicago,376,82,21,42,60,American,West,DH,0 254 | "Knight, Ray",New York,486,145,11,51,76,National,East,3B,16 255 | "Kutcher, Randy",San Francisco,186,44,7,28,16,National,West,OF,1 256 | "Law, Rudy",Kansas City,307,80,1,42,36,American,West,OF,2 257 | "Leach, Rick",Toronto,246,76,5,35,39,American,East,DO,1 258 | "Manning, Rick",Milwaukee,205,52,8,31,27,American,East,OF,2 259 | "Mulliniks, Rance",Toronto,348,90,11,50,45,American,East,3B,6 260 | "Oester, Ron",Cincinnati,523,135,8,52,44,National,West,2B,19 261 | "Quinones, Rey",Boston,312,68,2,32,22,American,East,SS,15 262 | "Ramirez, Rafael",Atlanta,496,119,8,57,33,National,West,S3,29 263 | "Reynolds, R.J.",Pittsburgh,402,108,9,63,48,National,East,LF,9 264 | "Roenicke, Ron",Philadelphia,275,68,5,42,42,National,East,OF,2 265 | "Sandberg, Ryne",Chicago,627,178,14,68,76,National,East,2B,5 266 | "Santana, Rafael",New York,394,86,1,38,28,National,East,SS,16 267 | "Schu, Rick",Philadelphia,208,57,8,32,25,National,East,3B,13 268 | "Sierra, Ruben",Texas,382,101,16,50,55,American,West,OF,6 269 | "Smalley, Roy",Minneapolis,459,113,20,59,57,American,West,DH,0 270 | "Thompson, Robby",San Francisco,549,149,7,73,47,National,West,2B,17 271 | "Wilfong, Rob",California,288,63,3,25,33,American,West,2B,7 272 | "Williams, Reggie",Los Angeles,303,84,4,35,32,National,West,CF,3 273 | "Yount, Robin",Milwaukee,522,163,9,82,46,American,East,CF,1 274 | "Balboni, Steve",Kansas City,512,117,29,54,88,American,West,1B,18 275 | "Bradley, Scott",Seattle,220,66,5,20,28,American,West,C,3 276 | "Bream, Sid",Pittsburgh,522,140,16,73,77,National,East,1B,17 277 | "Buechele, Steve",Texas,461,112,18,54,54,American,West,3B,11 278 | "Dunston, Shawon",Chicago,581,145,17,66,68,National,East,SS,32 279 | "Fletcher, Scott",Texas,530,159,3,82,50,American,West,SS,15 280 | "Garvey, Steve",San Diego,557,142,21,58,81,National,West,1B,7 281 | "Jeltz, Steve",Philadelphia,439,96,0,44,36,National,East,SS,22 282 | "Lombardozzi, Steve",Minneapolis,453,103,8,53,33,American,West,2B,6 283 | "Owen, Spike",Seattle,528,122,1,67,45,American,West,SS,17 284 | "Sax, Steve",Los Angeles,633,210,6,91,56,National,West,2B,16 285 | "Armas, Tony",Boston,425,112,11,40,58,American,East,CF,8 286 | "Bernazard, Tony",Cleveland,562,169,17,88,73,American,East,2B,17 287 | "Brookens, Tom",Detroit,281,76,3,42,25,American,East,UT,7 288 | "Brunansky, Tom",Minneapolis,593,152,23,69,75,American,West,RF,6 289 | "Fernandez, Tony",Toronto,687,213,10,91,65,American,East,SS,13 290 | "Flannery, Tim",San Diego,368,103,3,48,28,National,West,2B,3 291 | "Foley, Tom",Montreal,263,70,1,26,23,National,East,UT,4 292 | "Gwynn, Tony",San Diego,642,211,14,107,59,National,West,RF,4 293 | "Harper, Terry",Atlanta,265,68,8,26,30,National,West,OF,3 294 | "Harrah, Toby",Texas,289,63,7,36,41,American,West,2B,7 295 | "Herr, Tommy",St Louis,559,141,2,48,61,National,East,2B,9 296 | "Hulett, Tim",Chicago,520,120,17,53,44,American,West,3B,11 297 | "Kennedy, Terry",San Diego,432,114,12,46,57,National,West,C,8 298 | "Landrum, Tito",St Louis,205,43,2,24,17,National,East,OF,1 299 | "Laudner, Tim",Minneapolis,193,47,10,21,29,American,West,C,5 300 | "O'Malley, Tom",Baltimore,181,46,1,19,18,American,East,3B,9 301 | "Paciorek, Tom",Texas,213,61,4,17,22,American,West,UT,4 302 | "Pena, Tony",Pittsburgh,510,147,10,56,52,National,East,C,18 303 | "Pendleton, Terry",St Louis,578,138,1,56,59,National,East,3B,20 304 | "Perez, Tony",Cincinnati,200,51,2,14,29,National,West,1B,7 305 | "Phillips, Tony",Oakland,441,113,5,76,52,American,West,2B,11 306 | "Puhl, Terry",Houston,172,42,3,17,14,National,West,OF,0 307 | "Raines, Tim",Montreal,580,194,9,91,62,National,East,LF,6 308 | "Simmons, Ted",Atlanta,127,32,4,14,25,National,West,UT,6 309 | "Teufel, Tim",New York,279,69,4,35,31,National,East,2B,9 310 | "Wallach, Tim",Montreal,480,112,18,50,71,National,East,3B,16 311 | "Coleman, Vince",St Louis,600,139,0,94,29,National,East,LF,9 312 | "Hayes, Von",Philadelphia,610,186,19,107,98,National,East,1B,13 313 | "Law, Vance",Montreal,360,81,5,37,44,National,East,2B,3 314 | "Backman, Wally",New York,387,124,1,67,27,National,East,2B,17 315 | "Boggs, Wade",Boston,580,207,8,107,71,American,East,3B,19 316 | "Clark, Will",San Francisco,408,117,11,66,41,National,West,1B,11 317 | "Joyner, Wally",California,593,172,22,82,100,American,West,1B,15 318 | "Krenchicki, Wayne",Montreal,221,53,2,21,23,National,East,13,6 319 | "McGee, Willie",St Louis,497,127,7,65,48,National,East,CF,3 320 | "Randolph, Willie",New York,492,136,5,76,50,American,East,2B,20 321 | "Tolleson, Wayne",Chicago,475,126,3,61,43,American,West,3B,7 322 | "Upshaw, Willie",Toronto,573,144,9,85,60,American,East,1B,12 323 | "Wilson, Willie",Kansas City,631,170,9,77,44,American,West,CF,3 324 | -------------------------------------------------------------------------------- /data/sales_2000.csv: -------------------------------------------------------------------------------- 1 | store,year,sales 2 | 1,2000,117859.26873 3 | 2,2000,103643.14038 4 | 3,2000,103359.9152 5 | 4,2000,94314.629816 6 | 5,2000,119794.11043 7 | 6,2000,88621.612646 8 | 7,2000,90887.111027 9 | 8,2000,92743.397794 10 | 9,2000,79052.732804 11 | 10,2000,111462.78665 12 | 11,2000,112959.76441 13 | 12,2000,100705.68384 14 | 13,2000,101563.43782 15 | 14,2000,107971.63182 16 | 15,2000,105368.51408 17 | -------------------------------------------------------------------------------- /data/sales_2001.csv: -------------------------------------------------------------------------------- 1 | store,year,sales 2 | 1,2001,128945.43375 3 | 2,2001,123773.50123 4 | 3,2001,121418.29332 5 | 4,2001,108163.32016 6 | 5,2001,111802.90749 7 | 6,2001,126141.14374 8 | 7,2001,113112.01148 9 | 8,2001,98574.770774 10 | 9,2001,123448.31087 11 | 10,2001,104430.76823 12 | 11,2001,119732.2306 13 | 12,2001,128475.44855 14 | 13,2001,108157.67167 15 | 14,2001,116865.46411 16 | 15,2001,120720.57453 17 | -------------------------------------------------------------------------------- /data/sales_2002.csv: -------------------------------------------------------------------------------- 1 | store,year,sales 2 | 1,2002,128061.3114 3 | 2,2002,133618.75859 4 | 3,2002,118823.6527 5 | 4,2002,124382.30864 6 | 5,2002,114009.43816 7 | 6,2002,109729.81313 8 | 7,2002,108153.13571 9 | 8,2002,128289.54449 10 | 9,2002,111239.80269 11 | 10,2002,104704.42633 12 | 11,2002,122534.68247 13 | 12,2002,113034.39598 14 | 13,2002,115960.14813 15 | 14,2002,136428.62697 16 | 15,2002,110218.04173 17 | -------------------------------------------------------------------------------- /data/sales_2003.csv: -------------------------------------------------------------------------------- 1 | store,year,sales 2 | 1,2003,126824.58579 3 | 2,2003,139060.04404 4 | 3,2003,117347.77752 5 | 4,2003,130924.41318 6 | 5,2003,140842.65553 7 | 6,2003,132426.41465 8 | 7,2003,137914.59821 9 | 8,2003,122700.21104 10 | 9,2003,145883.7572 11 | 10,2003,129249.81963 12 | 11,2003,119236.03154 13 | 12,2003,129237.832 14 | 13,2003,129190.81888 15 | 14,2003,126691.323 16 | 15,2003,126222.92409 17 | -------------------------------------------------------------------------------- /data/sales_2004.csv: -------------------------------------------------------------------------------- 1 | store,year,sales 2 | 1,2004,142310.89767 3 | 2,2004,135310.77274 4 | 3,2004,141368.21517 5 | 4,2004,153307.29346 6 | 5,2004,123850.57326 7 | 6,2004,144118.0987 8 | 7,2004,149395.66297 9 | 8,2004,144149.12242 10 | 9,2004,146021.1003 11 | 10,2004,138955.52326 12 | 11,2004,133052.15782 13 | 12,2004,137545.61863 14 | 13,2004,139710.10711 15 | 14,2004,132890.54427 16 | 15,2004,140744.84292 17 | -------------------------------------------------------------------------------- /data/sales_2005.csv: -------------------------------------------------------------------------------- 1 | store,year,sales 2 | 1,2005,149355.86094 3 | 2,2005,131551.94075 4 | 3,2005,150997.62356 5 | 4,2005,143230.35522 6 | 5,2005,150207.645 7 | 6,2005,158151.74474 8 | 7,2005,145598.61927 9 | 8,2005,144716.697 10 | 9,2005,150943.73608 11 | 10,2005,149151.25493 12 | 11,2005,127085.59832 13 | 12,2005,161359.1011 14 | 13,2005,146879.25535 15 | 14,2005,145103.45872 16 | 15,2005,161145.07061 17 | -------------------------------------------------------------------------------- /data/sales_2006.csv: -------------------------------------------------------------------------------- 1 | store,year,sales 2 | 1,2006,157415.23834 3 | 2,2006,150666.8784 4 | 3,2006,155792.01393 5 | 4,2006,161154.70489 6 | 5,2006,169441.45806 7 | 6,2006,145877.6696 8 | 7,2006,153918.57892 9 | 8,2006,160355.91533 10 | 9,2006,160203.64144 11 | 10,2006,156651.57916 12 | 11,2006,153489.19327 13 | 12,2006,153308.85609 14 | 13,2006,179396.88282 15 | 14,2006,172248.1075 16 | 15,2006,179878.92436 17 | -------------------------------------------------------------------------------- /data/sales_2007.csv: -------------------------------------------------------------------------------- 1 | store,year,sales 2 | 1,2007,146217.79207 3 | 2,2007,179436.87924 4 | 3,2007,164226.11315 5 | 4,2007,169595.39731 6 | 5,2007,163146.24123 7 | 6,2007,162059.23352 8 | 7,2007,168897.89066 9 | 8,2007,171534.97973 10 | 9,2007,157878.83286 11 | 10,2007,176360.80751 12 | 11,2007,183144.06943 13 | 12,2007,162111.35023 14 | 13,2007,169448.02003 15 | 14,2007,177396.47476 16 | 15,2007,156541.07795 17 | -------------------------------------------------------------------------------- /data/sales_2008.csv: -------------------------------------------------------------------------------- 1 | store,year,sales 2 | 1,2008,169212.09669 3 | 2,2008,159704.13214 4 | 3,2008,163207.8774 5 | 4,2008,193012.00609 6 | 5,2008,180798.56442 7 | 6,2008,175440.9509 8 | 7,2008,164250.58236 9 | 8,2008,191095.62976 10 | 9,2008,166215.46717 11 | 10,2008,186668.59925 12 | 11,2008,177028.61966 13 | 12,2008,163970.8677 14 | 13,2008,198567.07606 15 | 14,2008,196397.90537 16 | 15,2008,186135.1334 17 | -------------------------------------------------------------------------------- /data/sales_2009.csv: -------------------------------------------------------------------------------- 1 | store,year,sales 2 | 1,2009,175689.09254 3 | 2,2009,172930.55966 4 | 3,2009,184073.40779 5 | 4,2009,199116.03693 6 | 5,2009,179107.5884 7 | 6,2009,180418.28433 8 | 7,2009,203761.66541 9 | 8,2009,181968.6834 10 | 9,2009,193823.06042 11 | 10,2009,195044.66953 12 | 11,2009,199332.54561 13 | 12,2009,186853.45005 14 | 13,2009,193359.28009 15 | 14,2009,171520.33742 16 | 15,2009,191630.20253 17 | -------------------------------------------------------------------------------- /data/state_pop.txt: -------------------------------------------------------------------------------- 1 | Alabama 4779736 2 | Alaska 710231 3 | Arizona 6392017 4 | Arkansas 2915918 5 | California 37253956 6 | Colorado 5029196 7 | Connecticut 3574097 8 | Delaware 897934 9 | Florida 18801310 10 | Georgia 9687653 11 | Hawaii 1360301 12 | Idaho 1567582 13 | Illinois 12830632 14 | Indiana 6483802 15 | Iowa 3046355 16 | Kansas 2853118 17 | Kentucky 4339367 18 | Louisiana 4533372 19 | Maine 1328361 20 | Maryland 5773552 21 | Massachusetts 6547629 22 | Michigan 9883640 23 | Minnesota 5303925 24 | Mississippi 2967297 25 | Missouri 5988927 26 | Montana 989415 27 | Nebraska 1826341 28 | Nevada 2700551 29 | New Hampshire 1316470 30 | New Jersey 8791894 31 | New Mexico 2059179 32 | New York 19378102 33 | North Carolina 9535483 34 | North Dakota 672591 35 | Ohio 11536504 36 | Oklahoma 3751351 37 | Oregon 3831074 38 | Pennsylvania 12702379 39 | Rhode Island 1052567 40 | South Carolina 4625364 41 | South Dakota 814180 42 | Tennessee 6346105 43 | Texas 25145561 44 | Utah 2763885 45 | Vermont 625741 46 | Virginia 8001024 47 | Washington 6724540 48 | West Virginia 1852994 49 | Wisconsin 5686986 50 | Wyoming 563626 -------------------------------------------------------------------------------- /data/state_pop.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/sas-prog-for-r-users/d68fee4f3276c8828bba7488b10103cb71285984/data/state_pop.xlsx -------------------------------------------------------------------------------- /notes/LWSP4R_001.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/sas-prog-for-r-users/d68fee4f3276c8828bba7488b10103cb71285984/notes/LWSP4R_001.pdf --------------------------------------------------------------------------------