SAS Sample Data Base

Download SAS Sample Data Base

Post on 28-Dec-2015

73 views

Category:

Documents

0 download

Embed Size (px)

DESCRIPTION

Req. for SAS exercises given in the book.

TRANSCRIPT

<ul><li><p>/*******************************************************************\ | Copyright (C) 2012 by SAS Institute Inc., Cary, NC, USA. | | | | SAS (R) is a registered trademark of SAS Institute Inc. | | | | This program sets up practice data for some of the examples || in the Certification Prep Guide: Base Programming for SAS 9. || || Last updated: Aug 7, 2012 |\*******************************************************************/ </p><p>options nosource nonotes nocardimage validvarname=V7 replace;</p><p> /* create sample data */</p><p>data _null_;</p><p> /* determine fileref paths, delimiters, file options */</p><p> length fileno fileyes $18 fileset $ 1024;</p><p> oshost=trim(substr(symget('sysscp'),1,2)); filepath=trim(pathname("sasuser")); if (oshost = "OS") and (length(symget('sysscp'))=2) then do; filepath=scan(filepath,1); dlm="."; fileno="disp=(new,catlg)"; fileyes="disp=(old,catlg)"; end; else do; host=trim(substr(symget('sysscp'),1,3)); if (host in ('WIN','OS2')) then do; filepath=trim(pathname("sasuser")); dlm="\"; fileno=""; fileyes=""; end; else if (host = "VMS") then do; filepath=""; dlm=""; fileno=""; fileyes=""; end; else do; filepath=trim(pathname("sasuser")); dlm="/"; fileno=""; fileyes=""; end; end;</p><p> /* assign filerefs */</p><p> array filelst1{8} $ filesas1-filesas8 ('accnt','accnt01','accnt02', 'accnt03',</p><p>https://support.sas.com/publishing/cert/sampdata.txt</p><p>1 of 164 23-Jun-14 11:25 PM</p></li><li><p> 'accnt04','activity','fee', 'printfee'); do i=1 to dim(filelst1); if (host = "CMS") then fileset=trim(filelst1(i)) || " sas *"; else fileset=trim(filepath) || dlm || trim(filelst1(i)) || ".sas"; isfile=fileexist(fileset); if isfile=1 then fileopts=trim(fileyes); else fileopts=trim(fileno); rc=filename(filelst1(i),fileset,"",fileopts); end;</p><p> array filelst2{47} $ filedt1-filedt47 ('admit','aprdata','aug99dat', 'bookdata','cardata','census','choldata','citydata','credit2','credit3', 'credit4','credit5','creditc','creditcard','creditcardcomma','data97', 'empdata','excdata1', 'excdata2','excdata3','exer','group3','invent','invent1','invent2', 'jan98dat','loan','memdata','newloans','orderdat','patdata','personel', 'phonesurvey','powerdat','pubdata','rawdata','salary','saledata','satdata1','satdata2', 'stordata','survey1','tempdata','tests','tests2','topten', 'vandata'); do i=1 to dim(filelst2); if (host="CMS") then fileset=trim(filelst2(i)) || " data *"; else fileset=trim(filepath) || dlm || trim(filelst2(i)) || ".dat"; isfile=fileexist(fileset); if isfile=1 then fileopts=trim(fileyes); else fileopts=trim(fileno); rc=filename(filelst2(i),fileset,"",fileopts); end;run;</p><p> /* create SAS programs*/</p><p>data _null_; infile cards4 missover length=l; length text $ 50; input text $varying50. l; file accnt03; put text;datalines4;data work.reliable;set clini.insure;where company='FRED SMYTHE;run;proc print data=work.reliablevar id name company total balancedue;run;;;;;run;</p><p>data _null_; infile cards4 missover length=l; length text $ 70; input text $varying70. l; file accnt04; put text;datalines4;data work.billing;set sasuser.insure;run;proc print data=work.billing keylabel;label total='Total Balance' balancedue='Balance Due';run;</p><p>https://support.sas.com/publishing/cert/sampdata.txt</p><p>2 of 164 23-Jun-14 11:25 PM</p></li><li><p>;;;;run;</p><p>data _null_; infile cards4 missover length=l; length text $ 50; input text $varying50. l; file accnt; put text;datalines4;data work.balance;set sasuser.insure;run;proc print data=work.balnce;run;;;;;run;</p><p>data _null_; infile cards4 missover length=l; length text $ 50; input text $varying50. l; file accnt02; put text;datalines4;data work.balnew2;set sasuser.insure;run;proc print data=work.balnew2var id name total balancedue;run;;;;;run;</p><p>data _null_; infile cards4 missover length=l; length text $ 50; input text $varying50. l; file accnt01; put text;datalines4;data work.balnew1;set sasuser.insure;run;proc print data=work.balnew1;var id name total balancedue;;;;;run;</p><p>data _null_; infile cards4 missover length=l; length text $ 50; input text $varying50. l; file activity; put text;datalines4;proc print data=sasuser.admit; var id name actlevel;run;;;;;</p><p>https://support.sas.com/publishing/cert/sampdata.txt</p><p>3 of 164 23-Jun-14 11:25 PM</p></li><li><p>run;</p><p>data _null_; infile cards4 missover length=l; length text $ 50; input text $varying50. l; file fee; put text;datalines4;data sasuser.admit2;set sasuser.admit;run;;;;;run;</p><p>data _null_; infile cards4 missover length=l; length text $ 50; input text $varying50. l; file printfee; put text;datalines4;</p><p>proc print data=sasuser.admit2;run;;;;;run;/* ***************************//* ***************************//* ***************************/ /* create raw data files*//* ***************************//* ***************************//* ***************************/data _null_; infile cards missover length=l; length text $ 50; input text $varying50. l; file admit pad lrecl=80; put text;datalines;2458 Murray, W 72 185 128 12 38 D2462 Almers, C 68 171 133 10 5 I2501 Bonaventure, T 78 177 139 11 13 I2523 Johnson, R 69 162 114 9 42 S2539 LaMance, K 75 168 141 11 46 D2544 Jones, M 79 187 136 12 26 N2552 Reberson, P 69 158 139 15 41 D2555 King, E 70 167 122 13 13 I2563 Pitts, D 71 159 116 10 22 S2568 Eberhardt, S 72 182 122 16 49 N2571 Nunnelly, A 65 181 141 15 2 I 2572 Oberon, M 74 177 138 12 11 D2574 Peterson, V 80 164 137 14 9 D2575 Quigley, M 74 152 113 11 26 I2578 Cameron, L 75 158 108 14 27 I2579 Underwood, K 72 165 127 13 19 S2584 Takahashi, Y 76 163 135 16 7 D2586 Derber, B 68 176 119 17 35 N2588 Ivan, H 70 182 126 15 41 N2589 Wilcox, E 78 189 138 14 57 I2595 Warren, C 77 170 136 12 10 S;</p><p>https://support.sas.com/publishing/cert/sampdata.txt</p><p>4 of 164 23-Jun-14 11:25 PM</p></li><li><p>data _null_; infile cards missover length=l; length text $ 50; input text $varying50. l; file aprdata pad lrecl=80; put text;datalines;Akron 04/05/99 04/09/99 175.00 298.45Brown 04/12/99 05/01/99 125.00 326.78Carnes 04/27/99 04/29/99 125.00 174.24Denison 04/11/99 04/12/99 175.00 87.41Fields 04/15/99 04/22/99 175.00 378.96Jamison 04/16/99 04/23/99 125.00 346.28;</p><p>data _null_; infile cards missover length=l; length text $ 50; input text $varying50. l; file aug99dat pad lrecl=80; put text;datalines;100 02AUG99 R 6 30.00 180.00103 03AUG99 C 20 3.99 79.80102 04AUG99 T 4 200.00 800.00103 08AUG99 T 5 200.00 1000.00102 09AUG99 R 15 30.00 450.00101 10AUG99 C 100 3.99 399.00101 12AUG99 R 18 30.00 540.00104 15AUG99 T 10 200.00 2000.00103 18AUG99 C 9 3.99 35.91100 22AUG99 T 3 200.00 600.00102 23AUG99 R 10 30.00 300.00100 25AUG99 C 100 3.99 399.00101 30AUG99 T 3 200.00 600.00;run;</p><p>data _null_; infile cards missover length=l; length text $ 50; input text $varying50. l; file bookdata pad lrecl=80; put text;datalines;AES358 PAPER 24AES358 HARDBACK 43AMZ114 PAPER 256AMZ114 HARDBACK 235ARS102 PAPER 28ARS102 HARDBACK 58ASD862 PAPER 287ASD862 HARDBACK 145AZX002 PAPER 17AZX002 HARDBACK 92BAE487 PAPER 67BAE487 HARDBACK 81BMW243 PAPER 120</p><p>https://support.sas.com/publishing/cert/sampdata.txt</p><p>5 of 164 23-Jun-14 11:25 PM</p></li><li><p>BMW243 HARDBACK 181BOP102 PAPER 228BOP810 HARDBACK 134BSX892 PAPER 73BSX892 HARDBACK 109BSY101 PAPER 187BSY101 HARDBACK 91BXT894 PAPER 0BXT258 HARDBACK 8BZZ543 PAPER 15BZZ543 HARDBACK 33;run;</p><p>data _null_; infile cards missover length=l; length text $ 50; input text $varying50. l; file cardata pad lrecl=80; put text;datalines;1998 US CARS 194,324.121998 US TRUCKS 142,290.301998 CANADA CARS 10,483.441998 CANADA TRUCKS 93,543.641998 MEXICO CARS 22,500.571998 MEXICO TRUCKS 10,098.881998 JAPAN CARS 15,066.431998 JAPAN TRUCKS 40,700.341997 US CARS 213,504.051997 US TRUCKS 116,735.651997 CANADA CARS 904.891997 CANADA TRUCKS 76,576.121997 MEXICO CARS 10,899.561997 MEXICO TRUCKS 13,000.451997 JAPAN CARS 10,000.181997 JAPAN TRUCKS 50,458.22;run;data _null_; infile cards missover length=l; length text $ 50; input text $varying50. l; file census pad lrecl=80; put text;datalines;H 321 S. MAIN STP MARY E 21 FP WILLIAM M 23 MP SUSAN K 3 FH 324 S. MAIN STP THOMAS H 79 MP WALTER S 46 MP ALICE A 42 FP MARYANN A 20 FP JOHN S 16 MH 325A S. MAIN STP JAMES L 34 MP LIZA A 31 F;data _null_; infile cards missover length=l;</p><p>https://support.sas.com/publishing/cert/sampdata.txt</p><p>6 of 164 23-Jun-14 11:25 PM</p></li><li><p> length text $ 50; input text $varying50. l; file choldata; file choldata pad lrecl=80; put text;datalines;BECKER ED429174.1DE HARTE ED102273.4JOHNSON MK832187.7LYLES SL934220.7MC CAULEYAD524202.3MORGAN AD243229.5PETERSON MK208259.4ROBERTS ED097203.7THOMAS SL029198.7VAN HORN MK148178.7;run;</p><p>data _null_; infile cards missover length=l; length text $ 50; input text $varying50. l; file citydata pad lrecl=80; put text;datalines;ANCHORAGE 48081 174431ATLANTA 495039 425022BOSTON 641071 562994CHARLOTTE 241420 314447CHICAGO 3369357 3005072DALLAS 844401 904078DENVER 514678 492365DETROIT 1514063 1203339MIAMI 334859 346865PHILADELPHIA 1949996 1688210SACRAMENTO 257105 275741;</p><p>data _null_; infile cards missover length=l; length text $ 50; input text $varying50. l; file credit2 pad lrecl=80; put text;datalines;MALE,,1,8,0,0FEMALE,29,3,14,5,10FEMALE,34,2,10,3,3MALE,35,2,12,4,8FEMALE,36,4,16,3,7;</p><p>data _null_; infile cards missover length=l; length text $ 50; input text $varying50. l; file credit3 pad lrecl=80; put text;datalines;MALE**1*8*0*0</p><p>https://support.sas.com/publishing/cert/sampdata.txt</p><p>7 of 164 23-Jun-14 11:25 PM</p></li><li><p>FEMALE*29*3*14*5*10FEMALE*34*2*10*3*3MALE*35*2*12*4*8FEMALE*36*4*16*3*7;</p><p>data _null_; infile cards missover length=l; length text $ 50; input text $varying50. l; file credit4 pad lrecl=80; put text;datalines;,27,1,8,0,0FEMALE,29,3,14,5,10FEMALE,34,2,10,3,3MALE,35,2,12,4,8FEMALE,36,4,16,3,7;</p><p>data _null_; infile cards missover length=l; length text $ 50; input text $varying50. l; file credit5 pad lrecl=80; put text;datalines;MALE 27 1 8 0 0FEMALE 29 3 14 5 10FEMALE 34 2 10 3 3MALE 35 2 12 4 8FEMALE 36 4 16 3 7;/* creditc goes with examples in Ch.17, p. 330, renamed because of conflict w/ data in end=of=chapter example */data _null_; infile cards missover length=l; length text $ 50; input text $varying50. l; file creditc pad lrecl=80; put text;datalines;MALE 27 1 8 0 0FEMALE 29 3 14 5 10FEMALE 34 2 10 3 3MALE 35 2 12 4 8FEMALE 36 4 16 3 7MALE 21 1 5 0 0MALE 25 2 9 2 1FEMALE 21 1 4 2 6MALE 38 3 11 4 3FEMALE 30 3 5 1 0;</p><p>data _null_; infile cards missover length=l; length text $ 50; input text $varying50. l; file creditcard pad lrecl=80; put text;datalines;EVANS#m#27#3#2</p><p>https://support.sas.com/publishing/cert/sampdata.txt</p><p>8 of 164 23-Jun-14 11:25 PM</p></li><li><p>HELMS#f#29#2#1LARSON#f#33#3#3HIGGINS#m#35#2#2MOORE#f#36#3#1POWELL#m#21#2#3RILEY#f#25#3#2;</p><p>data _null_; infile cards missover length=l; length text $ 50; input text $varying50. l; file creditcardcomma pad lrecl=80; put text;datalines;MALE,27,1,8,0,0FEMALE,29,3,14,5,10FEMALE,34,2,10,3,3MALE,35,2,12,4,8FEMALE,36,4,16,3,7MALE,21,1,5,0,0MALE,25,2,9,2,1FEMALE,21,1,4,2,6MALE,38,3,11,4,3FEMALE,30,3,5,1,0;data _null_; infile cards missover length=l; length text $ 50; input text $varying50. l; file data97 pad lrecl=80; put text;datalines;0734 1,323.34 2,472.85 3,276.65 5,345.520943 1,908.34 2,560.38 3,472.09 5,290.861009 2,934.12 3,308.41 4,176.18 7,581.811043 1,295.38 5,980.28 8,876.84 6,345.941190 2,189.84 5,023.57 2,794.67 4,243.351382 3,456.34 2,065.83 3,139.08 6,503.491734 2,345.83 3,423.32 1,034.43 1,942.281824 1,323.34 2,472.85 1943 1,908.34 2046 1,423.52 1,673.46 3,276.65 2063 2,345.34 2,452.45 3,523.52 2,983.01;data _null_; infile cards missover length=l; length text $ 50; input text $varying50. l; file excdata1 pad lrecl=80; put text;datalines;EVANS DONNY 112 29996.63HELMS LISA 105 18567.23HIGGINS JOHN 111 25309.00LARSON AMY 113 32696.78MOORE MARY 112 29945.89POWELL JASON 103 35099.50RILEY JUDY 111 25309.00;</p><p>data _null_;</p><p>https://support.sas.com/publishing/cert/sampdata.txt</p><p>9 of 164 23-Jun-14 11:25 PM</p></li><li><p> infile cards missover length=l; length text $ 50; input text $varying50. l; file excdata1 pad lrecl=80; put text;datalines;1001 sedentary 1002 daily 1003 moderate1004 sedentary 1005 moderate 1006 sedentary1007 daily 1008 daily 1009 moderate1010 sedentary 1011 daily 1012 sedentary1013 moderate 1014 moderate 1015 sedentary1016 daily 1017 moderate 1018 moderate1019 daily 1020 daily 1021 moderate1022 sedentary 1023 daily 1024 sedentary1025 moderate 1026 moderate 1027 sedentary1028 daily 1029 moderate 1030 moderate1031 daily 1032 daily 1033 moderate1034 sede...</p></li></ul>