81646619 Base Sas Certification Exercise

47
Session 1 [edit ] exercise 1 Fill in the blank: data test; _______ x 1-2 y 3-6 z 7-9; cards; 1 2 5 3 4 6 5 80 8 ; run; [edit ] exercise 2 Fill in the blanks: data cat; ______ 'C:\Documents and Settings\Yuan-Ting Wang\UserData\cat.txt'; ______ ID $ 1-4 AGE 6-7 SEX $ 8; run; [edit ] exercise 3 Write a program, similar to the previous exercise that will create a temporary dataset called Students (who are all cool cats). There are perhaps two (or more) ways to do this. One way uses the raw data file directly. Or you may assume that a temporary dataset (called cats, work.cats, or 'cats.sas7bdat'(in some folder) already exists. What changes should be made so that the DATA step reads only the first 15 observations? [edit ] exercise 4 Look at Example 1 in Session 1 : data test; input x y; cards; 1 2 3 4 5 80 ; run;

description

gud sas base

Transcript of 81646619 Base Sas Certification Exercise

Page 1: 81646619 Base Sas Certification Exercise

Session 1

[edit]

exercise 1

Fill in the blank: data test;_______ x 1-2 y 3-6 z 7-9;cards;1 2 53 4 65 80 8;run;[edit]

exercise 2

Fill in the blanks: data cat;______ 'C:\Documents and Settings\Yuan-Ting Wang\UserData\cat.txt';______ ID $ 1-4 AGE 6-7 SEX $ 8;run;[edit]

exercise 3

Write a program, similar to the previous exercise that will create a temporary dataset called Students (who are all cool cats). There are perhaps two (or more) ways to do this. One way uses the raw data file directly. Or you may assume that a temporary dataset (called cats, work.cats, or 'cats.sas7bdat'(in some folder) already exists. What changes should be made so that the DATA step reads only the first 15 observations? [edit]

exercise 4

Look at Example 1 in Session 1 : data test;input x y;cards;1 23 45 80;run;

Page 2: 81646619 Base Sas Certification Exercise

How many times does SAS execute the INPUT statement when the program is submitted?

[edit]

exercise 5

In example 6: data scores; infile datalines _______; input score1-score5; datalines;90 98 9880 100 98 70 7820 50 90 30 60;run;proc print data=scores;run;If you know there are five tests in the semester, the first person missed the last two tests and she got 90 98 98 in the first three tests. The second person got 80 100 98 70 78, and the third person got 20 50 90 30 60. Then which options should you use to present the correct data set. [edit]

exercise 6

In Example 5: data test;input x y z;cards;1 2 43 4 75 80 36 20 29 30 1;run;proc print data=test (firstobs=2);run;Which changes should be made if you only want to read the first three observations? And which changes should be made if you want to read the second and the third observations? [edit]

Session 2

Page 3: 81646619 Base Sas Certification Exercise

[edit]

exercise 1

In example 3.2 data sealife;input name $ family $ length ;datalines;beluga whale 15whale shark 40basking shark 30gray whale 50mako shark 12sperm whale 60dwarf shark .5whale shark 40humpback . 50blue whale 100killer whale 30;run;

Write a program to create a new data set called newsealife, and set a new variable-newlength which presents the length in two decimal points. And print out the new data set with only the new variable-newlength. Hint: the output should look like below Obs newlength 1 15.00 2 40.00 3 30.00 4 50.00 5 12.00 6 60.00 7 0.50 8 40.00 9 50.00 10 100.00 11 30.00[edit]

exercise 2

In example 3.4 Name ClassRm Month Day Year Candy Quantity Adriana 21 3 2 2000 MP 7Nathan 14 2 28 2000 CD 19Matthew 14 3 1 2000 CD 14Claire 14 3 3 2000 CD 11Caitlin 21 2 24 2000 CD 9Ian 21 3 3 2000 MP 18Chris 14 2 18 2000 CD 6

Page 4: 81646619 Base Sas Certification Exercise

Anthony 21 6 1 2000 MP 13Stephen 14 3 25 2000 CD 10Erika 21 3 25 2000 MP 17Create a program which shows the min and the max of the quantity. Hint: The output should look like below: Analysis Variable : Quantity Minimum Maximum ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 6.0000000 19.0000000 ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ [edit]

exercise 3

Follow the previous exercise. Group the candy into two groups. Call the Candy with quantity less than 12 "1", and call the other "2". And then print out the result. Hint: The output should look like below Obs group1 12 23 24 15 16 27 18 29 110 2[edit]

exercise 4

Follow the previous exercise, sort the data by group. And calculate the mean quantity of each group. Hint: the output should look like below --------------------------------------------- group=1 The MEANS Procedure Analysis Variable : Quantity Mean ------------ 8.6000000 --------------------------------------------------------- group=2 Analysis Variable : Quantity Mean ------------ 16.2000000 ------------[edit]

Page 5: 81646619 Base Sas Certification Exercise

exercise 5

Instead of creating the seperate tables above, what changes are you going to make if you want a single table like below: Analysis Variable : Quantity N group Obs Meanƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 1 5 8.6000000 2 5 16.2000000ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

[edit]

Session 3

[edit]

Exercise 1

Use the data in example 3.4 to create a HTML page which has the title Candy Data , and shows the correlation between quantity of the candy and the classroom. Finally, save the HTML page in your computer: Hint: Use the html , title option in ods statement. And the Proc statement. [edit]

Exercise 2

Use the data in Session 4.4. Use the round function for SDAR, the substr function to choose the first five characters of the name variale, and sort the data by the first five characters of the name. [edit]

Exercise 3

Use the data in Example 4.5 to calculate the average minutes that students spend on the homework per day. Hint: using the mean function. [edit]

Exercise 4

Use the example 4.6. Set an array T to describe the Women's and men's Salary in thousands. Hint: T[i]=T[i]*1000 [edit]

Page 6: 81646619 Base Sas Certification Exercise

Session 4

[edit]

Exercise 1

Use the data in example 2.1. Run the regression with the independent variables-weight and RestPulse and the dependent variable-age. Remove those observations with the absolute value of the residual larger than 8, and re-run the program again. Use the option outest to compare the results you get. Hint: use the option r in output statement to calculate the residual. [edit]

Exercise 2

Follow the previous example. Do the plot option in proc statment and see the relation between age and weight. [edit]

Exercise 3

Create the data called month. Use do loop to get the output which has 12 months. Merge the month data and the data below-the frequency of speeding per month: datalines;2 3 2 1 3 6 8 9 10 13 212 ;Print out the data you just merged, and see what it looks like. [edit]

Session 5

[edit]

exercise 1

Page 7: 81646619 Base Sas Certification Exercise

Use the example below: data phone;input City $11. @12 State $ Zip $ Phonenum $;cards;cary NC 27513 6224549cary NC 27513 6223251chapel-hill NC 27514 9974794raleigh NC 27612 6970450raleigh NC 27612 6791125cary NC 27513 6224550;run;proc print data=phone;run;Use substr function to limit the first three numbers in phone number. Use length function to see how many characters the city has. [edit]

exercise 2

Variable:yearY = Index of Real Compensation per Hour, 1982=100X = Index of Output per Hour, 1982=1001982 100.0000 100.00001983 100.5000 102.00001984 100.4000 104.60001985 101.3000 106.10001986 104.4000 108.30001987 104.3000 109.40001988 104.4000 110.40001989 103.0000 109.50001990 103.2000 109.70001991 103.9000 110.1000Use the information above to run the regression with the dependent variable-Y and independent variable-X. See the relationship between the compensation and output per hour. [edit]

exercise 3

According to the previous data, you want to change the index base to 1 not 100. What change should you make? Will that affect the result of the regression? Hint:Apply the informat function in your codes or creat new variables.

[edit]

exercise 4

Page 8: 81646619 Base Sas Certification Exercise

Use the data below: Y X2 X3 10 1 1 8 2 3 6 3 5 4 4 7 2 5 9 0 6 11 2 7 13Treat Y is the dependent variable and X3 is independent variable. Take log on both sides, and compare the regression with log and without log. [edit]

exercise 5

Go to the US. census Bureau website, and findout the 2005 3rd quarter data in Federal Assistance Award Data System. Download the flat data file and try to import the data into your SAS program. Print out the first 15 observations for variables- COUNTY_NAME F_FUNDS T_FUNDS. Compare the output and the original excel data file, see if you get the correct print out. If you are interested in the data, you can read FAADS User Guide, and see how to use the data. If you can't find the flat data file, here is the link [1] [edit]

Session 6

Use the data "air" in sashelp. Format the variable date into julday. Also try to informat the variable date into numbers of day. And explain why you get negative value in date in this case. Hint: Since the "informat" must follow by the input statement, you have to put infile statement too. But never use infile to read sashelp data, because infile statement can only read text file. So what you may do is to save the sas data file into text file then use it in the infile statement. [edit]

Session 7

[edit]

exercise 1

Follow questions in /* */ and complete the codes we did in the course. Please fill out all the blank below:

Page 9: 81646619 Base Sas Certification Exercise

data airt;set sashelp.air;day=day(date);mo=month(date);yr=year(date);decade=(int(yr/10)-190)*10;run;

proc print data=airt;run;

data airt;set airt;drop day date;run;/*define a new variable-mair which stands for the maximum value of air line travel in each decade*/proc ____ data=airt;__ decade;var air;output out=maxair ___=mair;run;

proc print data=maxair;run;data test;set maxair;drop _type_ _freq_;run;/*Save the test data file into the permanent sas file*/data '_____________________';set ____;run;

data airmax;set 'c:\temp\airmax.sas7bdat';run;/*Now you want to merge the data airmax and airt by decade. And define a new variable relative=((mair-air)/mair)*100. Fill out the blank below*/proc sort data=airmax;___ decade;run;proc print data=airmax;run;

proc ____ data=airt;___ decade;run;

proc print data=airt;run;

data final;____ airt airmax;___ decade;

Page 10: 81646619 Base Sas Certification Exercise

relative=((mair-air)/mair)*100;run;

proc print data=final;run;[edit]

exercise 2

Go to the website of US. Department of Labor: [2] Find the data file describes the population-employment ratio for white male until 2002. And if now you have data in 2002 and 2003 looks like below: Year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 2003 74.4 74.4 74.2 74.2 74.1 74.0 74.0 73.8 73.9 73.7 73.3 73.3 2004 72.7 73.2 72.8 72.9 73.1 73.1 73.1 73.2 73.0 72.9 72.7 72.4 Try to combine those two data sets. [edit]

exercise 3

If the new data you get includes 2002-2004 instead of 2003-2004, then there will be a duplicate data for 2002 after you combine the old data and new data. How would you fix the problem? Which SAS options are you going to use? [edit]

Session 8

[edit]

exercise 1

Use the soup example introduced in the workshop. Try to count the soup which is made by chicken. Hint: You can use SUBSTR or INDEX to solve the problem. [edit]

Session 9

[edit]

exercise 1

Use the Example for Model Procedure in SAS Certification Examples(part 2).

Page 11: 81646619 Base Sas Certification Exercise

1.Plot the original data 2.Apply the economic model: population = a / ( 1 + exp( b - c * (year-1790) ) ) where a=Maximum Population. b=Location Parameter. c=Initial Growth Rate. Use Model Procedure to estimate a, b and c note:a should start from 1000, and b shoud start from 5.5 and c should start from 0.02 in SAS you can write: start=(a 1000 b 5.5 c .02) 3.plot the model you estimate.

Session 6

[edit]

Example 1

data test;file 'c:\Temp\myfile.txt';x=10; y=20;put x;put y;output;x=3; y=36;put x;put y;put 'All done.';run;

Try putting a * in front of the file statement. Run the code clip again and look what's in the LOG. After making a dataset in SAS, it becomes a temporary .sas7bdat file in a WORK library that is cleared when you close the SAS session. data test;x=10; y=20;output;run;Before you close SAS you can simple read it by using a set statement. Here's an example of reading a plain text file data testds;infile 'c:\Temp\myfile.txt';input x;run;

proc print data=testds;run;[edit]

Page 12: 81646619 Base Sas Certification Exercise

Example 2

Strings data strings1;infile 'c:\Temp\strings.txt';input id month $ grade $1. correct total;run;

proc print data=strings1;run;The $1. is an INformat. An informat always has a . (dot) in it.

Without an informat specification on the INPUT statement SAS may have some difficulty determining what length to make the placeholder for the textual information in a column. data strings1;infile 'c:\Temp\strings.txt';input id month $ grade $ correct total;run;

proc print data=strings1;run;To assist SAS with correctly jumping to a column where we expect certain data to reside on each record/row we use pointer control (using the @ sign on the INPUT statement). data justyr;infile 'c:\Temp\strings.txt';input @10 yr @13 grade $1. @15 correct total;run;

proc print data=justyr;run;[edit]

Example 3

Using Informats to do more. data strings2;input id month $ grade $upcase1. correct total major $20.;cards;101 10-2006 A 12 14 Economics101 11-2006 A 15 15 Econ101 12-2006 B 15 20 economics101 1-2007 a 15 15 econ102 10-2006 c 10 14 Psychology102 12-2006 C 12 20 Psych102 01-2007 B 13 15 PSYCH103 10-2006 a 14 14 Econ103 11-2006 B 12 15 Econ103 12-2006 B 16 20 Econ104 01-2007 A 15 15 Decker School of Nursing;

Page 13: 81646619 Base Sas Certification Exercise

run;

proc print data=strings2;run;[edit]

Example 4

Using common string functions. data str3;set strings2;m=substr(month,1,2);maj=substr(major,1,4);l=length(major);lenm=length(month);run;

data str4;set strings2;maj=upcase(substr(major,1,4));run;[edit]

Example 4a

A short practical use of converting everything to upper case and using a 'subsetting IF' statement. data econ;set str4;if (maj='ECON');run;

proc means data=econ;var correct;run;

proc print data=econ;run;

Other functions (acting on character strings) /*indexanyloweranyupper if 'a'='A' then do; end;anyspace if upcase('a')=upcase('A') then do; end;*/[edit]

Example 5

INformats for numbers.

Page 14: 81646619 Base Sas Certification Exercise

data numbers;input n 4.1 @6 n2 ;cards;01234567891089128273849999996666 103;run;

proc print data=numbers;run;[edit]

Closing examples

data stringok;input @21 majorcap $upcase4.; cards; 101 10-2006 A 12 14 Economics101 11-2006 A 15 15 Econ101 12-2006 B 15 20 economics101 1-2007 a 15 15 econ102 10-2006 c 10 14 Psychology102 12-2006 C 12 20 Psych102 01-2007 B 13 15 PSYCH103 10-2006 a 14 14 Econ103 11-2006 B 12 15 Econ103 12-2006 B 16 20 Econ104 01-2007 A 15 15 Decker School of Nursing;run;

proc print data=stringok;run;

data stringweird;input @21 majorcap $revers4.; cards; 101 10-2006 A 12 14 Economics101 11-2006 A 15 15 Econ101 12-2006 B 15 20 economics101 1-2007 a 15 15 econ102 10-2006 c 10 14 Psychology102 12-2006 C 12 20 Psych102 01-2007 B 13 15 PSYCH103 10-2006 a 14 14 Econ103 11-2006 B 12 15 Econ103 12-2006 B 16 20 Econ104 01-2007 A 15 15 Decker School of Nursing;run;

proc print data=stringweird;

Page 15: 81646619 Base Sas Certification Exercise

run;

[edit]

Session 7

No data for today. We'll use datasets in the SASHELP library, or files that we explicitly create in class. Be sure to look at the references (listed at 'Essential Readings') for functions and functions by category (to find those listed for SAS Dates and Times). We'll be speaking about date/time related Formats, and Informats today as well. To look at what's possible with SAS graphics the SAS/Graph overview is an excellent place to start. [edit]

In class

data test;x=today();x1=today()+1;x2='3

SAS Certification ExamplesFrom BingWiki

Jump to: navigation, searchBack to SAS Certification Examples and Exercises (Part 1)

Contents

[hide]

• 1 Session 1 o 1.1 Example 1 o 1.2 Example 2

• 2 Session 2 o 2.1 Example 1 o 2.2 Example 2 o 2.3 Example 3 o 2.4 Example 4 o 2.5 Example 5 o 2.6 Example 6

Page 16: 81646619 Base Sas Certification Exercise

o 2.7 Example 7 • 3 Session 3

o 3.1 Example 1 o 3.2 Example 2 o 3.3 Example 3 o 3.4 Example 4

• 4 Session 4 o 4.1 Examples (part 1) o 4.2 Example 2 (skipped) o 4.3 Example 3 (actually just a part 2) o 4.4 Example 4 o 4.5 Example 5 o 4.6 Example 6

• 5 Session 5 o 5.1 Example 1 o 5.2 Example 2 o 5.3 Example 2a o 5.4 Example 2b o 5.5 Example 3 o 5.6 Example 4 o 5.7 Example 4a o 5.8 Example 5

• 6 SAS_Certification_Examples(part_2) [edit]

Session 1

You can select and copy each one of the following examples and paste them directly into your SAS Editor window. They should each run without errors. [edit]

Example 1

data test;input x y;cards;1 23 45 80;run;

• Notice that a dataset is created, but no output is produced. What's missing from the program?

Page 17: 81646619 Base Sas Certification Exercise

• The dataset has 3 observations and 2 variables.

After the line that says 5 80 add a new line that says 6 .Run the whole program again. Notice that SAS does not produce an error message. [edit]

Example 2

Taken from the SAS Online Documentation, Example from the PROC REG procedure. data fitness; input Age Weight Oxygen RunTime RestPulse RunPulse MaxPulse @@; datalines; 44 89.47 44.609 11.37 62 178 182 40 75.07 45.313 10.07 62 185 185 44 85.84 54.297 8.65 45 156 168 42 68.15 59.571 8.17 40 166 172 38 89.02 49.874 9.22 55 178 180 47 77.45 44.811 11.63 58 176 176 40 75.98 45.681 11.95 70 176 180 43 81.19 49.091 10.85 64 162 170 44 81.42 39.442 13.08 63 174 176 38 81.87 60.055 8.63 48 170 186 44 73.03 50.541 10.13 45 168 168 45 87.66 37.388 14.03 56 186 192 45 66.45 44.754 11.12 51 176 176 47 79.15 47.273 10.60 47 162 164 54 83.12 51.855 10.33 50 166 170 49 81.42 49.156 8.95 44 180 185 51 69.63 40.836 10.95 57 168 172 51 77.91 46.672 10.00 48 162 168 48 91.63 46.774 10.25 48 162 164 49 73.37 50.388 10.08 67 168 168 57 73.37 39.407 12.63 58 174 176 54 79.38 46.080 11.17 62 156 165 52 76.32 45.441 9.63 48 164 166 50 70.87 54.625 8.92 48 146 155 51 67.25 45.118 11.08 48 172 172 54 91.63 39.203 12.88 44 168 172 51 73.71 45.790 10.47 59 186 188 57 59.08 50.545 9.93 49 148 155 49 76.32 48.673 9.40 56 186 188 48 61.24 47.920 11.50 52 170 176 52 82.78 47.467 10.50 53 170 172 ; run;proc reg data=fitness; model Oxygen=RunTime; run;[edit]

Session 2

To understand the differences in the SAS Statments-INPUT and INFILE, See the following examples. [edit]

Example 1

The INFILE statement is to identify an external file. In SAS, it will be like: FILENAME CAT 'C:\USERS\CAT.DAT';DATA PETS;

Page 18: 81646619 Base Sas Certification Exercise

INFILE CAT;INPUT ID $ 1-4 AGE 6-7 SEX $ 8;RUN;Notice that the CAT is the name of your external file. Note: DATA statement is to NAME a SAS data set. [edit]

Example 2

The INPUT statment is to describe your data. In SAS, it will be like: FILENAME CAT 'C:\USERS\CAT.DAT';DATA PETS;INFILE CAT;INPUT ID $ 1-4 AGE 6-7 SEX $ 8;RUN;Notice that the dollar sign idenfities the variable type as character.Since it's meaningless to run the regression if you treat the ID as numeric variable.And the INPUT statement here assigns the character variable ID to the data in columns 1-4,the numeric variable AGE to the data in columns 6-7, the character variable SEX to the data incolumn 8.[edit]

Example 3

There is a useful statement-OBS which can be used in the INFILE statement. Situation: When you have 1000000 observations in your data set, and you want to take a lookat it without reading the entire data file. You can add OBS=n to the INFILE satement, so that you can process only records 1 through n. FILENAME CAT 'C:\USERS\CAT.DAT';DATA PETS;INFILE CAT OBS=10;INPUT ID $ 1-4 AGE 6-7 SEX $ 8;RUN;Notice that you only run the first ten observations here. [edit]

Example 4

The data statements of this example make use of a new feature called direct referencing (version 9.1). By using this new feature we avoid the added step of using a FILENAME statement. Note: this example won't run without errors since in class we used File Import in the SAS menu to create a WORK.Class1 dataset.

Page 19: 81646619 Base Sas Certification Exercise

Here is the raw text that belongs in a file called class1.txt in the C:\Temp folder (from an Excel spreadsheet). id age name 1 19George 2 20Mary 3 21Xena 4 21Juanproc print data=class1 (firstobs=3 obs=4);var id age;run;

proc means data=class1;run;

data class2;infile 'c:\Temp\class1.txt' firstobs=2 truncover;input id 1-8 age 9-16 name $ 17-24;run;

proc print data=class2;run;

data 'c:\Temp\plato.sas7bdat';set class1;run;

data test;input x y;cards;1 23 45 806 16000;run;

data 'c:\Temp\test.sas7bdat';set test;run;

[edit]

Example 5

FIRSTOBS: To specify which observation SAS processes first. data test;input x y z;cards;1 2 43 4 75 80 36 20 29 30 1

Page 20: 81646619 Base Sas Certification Exercise

;run;

proc print data=test (firstobs=2);run;Run the whole example in your computer and notice that you only print out the last four observations in output. [edit]

Example 6

MISSOVER: To prevent an INPUT statement from reading a new input data record if it does not find values in the current input line for all the variables in the statement. --from SDLEo data scores; infile datalines missover; input score1-score5; datalines;90 98 9880 100 98 70 7820 50 90 30 60;run;proc print data=scores;run;Run the above program and notice the missing value in the ouput window. [edit]

Example 7

Change the option-MISSOVER to FLOWOVER and TRUNCOVER in the previous example, and see what's the difference. [edit]

Session 3

[edit]

Example 1

data test;input f1;cards;1230000.00040.0005

Page 21: 81646619 Base Sas Certification Exercise

6.670365366367;run;

data test2;set test;f2=f1;f3=f1;f4=f1;f5=f1;format f2 8.2 ;format f3 date9. ;format f4 dollar8.2 ;format f5 8.0 ;run;

proc print data=test2;run;[edit]

Example 2

Great white sharks (Wikipedia article) are killing machines that have not needed to evolve for millions of years. An extended example. The data records the average length in feet of selected whales and sharks. data sealife;input name $ family $ length ;datalines;beluga whale 15whale shark 40basking shark 30gray whale 50mako shark 12sperm whale 60dwarf shark .5whale shark 40humpback . 50blue whale 100killer whale 30;run;

proc means data=sealife mean;var length;run;

proc means data=sealife min max;class family;

Page 22: 81646619 Base Sas Certification Exercise

var length;run;

proc sort data=sealife out=sortedlife;by descending length ;run;

proc print data=sortedlife;var name family length;run;

proc sort data=sealife out=sealife2;by family descending length ;run;proc print data=sealife2;var name family length;run;

proc means data=sealife noprint nway;class family;var length;output out=ds35;run;

proc sort data=sealife out=sl2;by family;run;

proc means data=sl2;var length;by family;run;[edit]

Example 3

Using the fitness example from the earlier session we looked at a common usage for PROC SORT data fit2;set fitness;* Here's a simple calculation that will give us two age groups;agecat=1; /* The 'young' age category */if (age>50) then agecat=2; /* 'old' */run;

proc print data=fit2;var age agecat Oxygen RestPulse;run;

proc sort data=fit2 out=jerry;by agecat;run;

proc corr data=jerry;

Page 23: 81646619 Base Sas Certification Exercise

var Oxygen RestPulse;by agecat;run;A separate Correlation report is produced for each Age category. [edit]

Example 4

Candy sales data, similar to the data mentioned in The Little SAS Book, Section 4.4 (light blue edition, page 107). Name ClassRm Month Day Year Candy Quantity Adriana 21 3 2 2000 MP 7Nathan 14 2 28 2000 CD 19Matthew 14 3 1 2000 CD 14Claire 14 3 3 2000 CD 11Caitlin 21 2 24 2000 CD 9Ian 21 3 3 2000 MP 18Chris 14 2 18 2000 CD 6Anthony 21 6 1 2000 MP 13Stephen 14 3 25 2000 CD 10Erika 21 3 25 2000 MP 17Briefly editting the text above we wrote the program to illustrate two ways to use PROC FREQ. data candy;input Name $ ClassRm Month Day Year Candy $ Quantity ;cards;Adriana 21 3 2 2000 MP 7Nathan 14 2 28 2000 CD 19Matthew 14 3 1 2000 CD 14Claire 14 3 3 2000 CD 11Caitlin 21 2 24 2000 CD 9Ian 21 3 3 2000 MP 18Chris 14 2 18 2000 CD 6Anthony 21 6 1 2000 MP 13Stephen 14 3 25 2000 CD 10Erika 21 3 25 2000 MP 17;run;

proc freq data=candy;tables ClassRm Candy;run;

proc freq data=candy;tables ClassRm*Candy /nopercent norow;run;

[edit]

Session 4

Page 24: 81646619 Base Sas Certification Exercise

[edit]

Examples (part 1)

Height/Weight data showing very basic ODS statement usage data htwt; input Name $ 1-10 Sex $ 12 Age 14-15 Height 17-18 Weight 20-22; datalines;ALFRED M 14 69 112ALICE F 13 56 84BARBARA F 14 62 102BERNADETTE F 13 65 98HENRY M 14 63 102JAMES M 12 57 83JANE F 12 59 84JANET F 15 62 112JEFFREY M 13 62 84JOHN M 12 59 99JOYCE F 11 51 50JUDY F 14 64 90LOUISE F 12 56 77MARY F 15 66 112PHILLIP M 16 72 150ROBERT M 12 64 128RONALD M 15 67 133THOMAS M 11 57 85WILLIAM M 15 66 112;run;

proc corr data=htwt;var height weight;run;

ods listing close;proc print data=htwt;var height weight;run;Notice the error message that occurs when there is no active Output Destination (above). The following is a simple, very controlled way of directing where the output from a procedure should go ... and in what format you'd like to make the output. Other popular choices for output formats are:

• PDF • RTF (Rich Text Format)

ods html file='c:\Temp\corr.html';title 'The relationship between heights and weights';proc corr data=htwt;var height weight;run;

Page 25: 81646619 Base Sas Certification Exercise

ods html close;ODS and function examples using Tomato data (from the Little SAS Book, 3rd edition, Section 5.3) ods html file='c:\Temp\print2.html';ods listing; /* Turns the listing output destination back on */data tomatoes;input name $13. color $ Days Weight ;cards;Big Zac red 80 5Delicious red 80 3Dinner Plate red 90 2Goliath red 85 1.5Mega Tom red 80 2Big Rainbow yellow 90 1.5Pineapple yellow 85 2;run;

proc print data=tomatoes;run;

ods trace on;proc corr data=tomatoes;var Days Weight;run;ods trace off;* Examine the LOG to see what the names are for the various output components;ods trace on;proc corr data=tomatoes nosimp; /* This nosimp option reduces the number of tables produced */var Days Weight;run;ods trace off;

proc corr data=tomatoes;ods select Corr.PearsonCorr;var Days Weight;run;Now, on to limiting the observations output by a datastep, functions and creating new variables. data tom2;set tomatoes;if (Days>80);*if (Days <= 80) then delete;run;

proc print data=tom2;run;

data tom3;set tomatoes;newsum=Days+Weight;r=round(Weight);first3=substr(Name,1,3);

Page 26: 81646619 Base Sas Certification Exercise

spacepos=index(name,' ');caps=upcase(Name);leng=length(Name);run;

proc print data=tom3;run;[edit]

Example 2 (skipped)

The following was not covered in class due to time contraints. The data is derived from the Little SAS Book, 3rd edition, Section 5.11. (I was lazy about typing last names. --Rhansen 13:27, 28 September 2006 (EDT)) Traffic-Lighting Data 1, Jochem Smith, Netherlands,374.662, Derek Smith, United States,377.983, Jens Smith, Germany,381.734, Dmitry Smith, Russia,381.855, KC Smith, United States,382.97[edit]

Example 3 (actually just a part 2)

Baseball data, illustrating arrays and Do loops The following is not a proper reading of data mention in both editions of The Little SAS Book (2nd and 3rd editions) in the chapter about Simple Regression analyses. To illustrate a practicle use of arrays we've pretended that each T-ball player tries to hit a ball five times, rather than treating all 30 height/distance pairs as separate players. data baseball;input Height1 Distance1 Height2 Distance2 Height3 Distance3 Height4 Distance4 Height5 Distance5;cards;50 110 49 135 48 129 53 150 48 12450 143 51 126 45 107 53 146 50 15447 136 52 144 47 124 50 133 50 12850 118 48 135 47 129 45 126 48 11845 121 53 142 46 122 47 119 51 13449 130 46 132 51 144 50 132 50 131;run;

data bb2;set baseball;array H {5} Height1 Height2 Height3 Height4 Height5;do i=1 to 5;H{i}=H{i}*2.54; /* To convert inches to centimeters */

Page 27: 81646619 Base Sas Certification Exercise

end;run;

proc print data=bb2;run;

data simple;input x;cards;12 56;run;

data newsimp;set simple;do i=1 to 3;output;end;run;

proc print data=newsimp;run;[edit]

Example 4

COMPANY = Mutual Fund Company RETURN = Average Annual Return, Percent SDAR = Standard Deviation of Annual Return, Percent Name Return SDAR Group Securities. Common Stock Fund 15.1 19.1 Incorporated Investors 14.0 25.5 Investment Company of America 17.4 21.8 Investors Mutual 11.3 12.5 Loomis-Sales Mutual Fund 10.0 10.4 Massachusetts Investors Trust 16.2 20.8 National Investors Corporation 18.3 19.9 National Securities-Income Series 12.4 17.8 New England Fund 10.4 10.2 Massachusetts Investors-Growth Stock 18.6 22.7 Group Securities. Fully Administered Fund 11.4 14.1

[edit]

Example 5

Time:Total minutes spent on homework per week.Days:Days spent on homework per week.Time Days100 3

Page 28: 81646619 Base Sas Certification Exercise

150 4 99 5 . 6160 3 80 .200 3

[edit]

Example 6

FIELD = Field of Specialization WOMEN = Median Salaries of Women, Thousands of $ MEN = Median Salaries of Men, Thousands of $ FIELD WOMEN MEN Business, Finance, Etc. 9.3 13.0 Labor Economics 10.3 12.0 Monetary-Fiscal 8.0 11.6 General Economic Theory 8.7 10.8 Population, Welfare Programs, Etc. 12.0 11.5 Economic Systems and Development 9.0 12.2

[edit]

Session 5

[edit]

Example 1

Simple examples to illustrate simple dataset creation. data test;x=1;a=2;b=3;c=18;run;

data test2;set test;y=32;d=a+b;run;

data test3;set test2;output;output;output;run;[edit]

Page 29: 81646619 Base Sas Certification Exercise

Example 2

Examples for generating a sequence of year values data alumni;year=1995;contrib=1000;output;year=year+5;contrib=1500;output;year=year+5;output;year=year+5;output;run;

data alumni;year=1995;output;year=year+5;contrib=1500;output;year=year+5;output;year=year+5;output;run;

data alumni50;year=1995;contrib=1000;do i=1 to 10; contrib=contrib+25; year=year+5; output; end;run;

proc print data=alumni50;run;

data pop;year=1790;output;do i=1 to 21;year=year+10;output;end;run;

proc print data=pop;run;[edit]

Page 30: 81646619 Base Sas Certification Exercise

Example 2a

Combining a sequence with real data of US Population estimates starting in 1790 (Data from the SAS online documentation PROC REG (regression) overview.) data actpop;input population;cards;3.9295.3087.2399.63812.86617.06923.19131.44339.81850.15562.94775.99491.972105.71122.775131.669151.325179.323203.211226.542248.71281.422;run;data fullpop;merge pop actpop;run;proc print data=fullpop;run;

[edit]

Example 2b

Using the population data for a quick linear regression. Actually looking at the plot reveals what a poor fit the linear model is. proc gplot data=fullpop;plot population*year;run;

proc reg data=fullpop;model Population=year;run;[edit]

Page 31: 81646619 Base Sas Certification Exercise

Example 3

Heights, Weights and Ages for a class. data class;input Name $ Height Weight Age @@;datalines; Alfred 69.0 112.5 14 Alice 56.5 84.0 13 Barbara 65.3 98.0 13 Carol 62.8 102.5 14 Henry 63.5 102.5 14 James 57.3 83.0 12 Jane 59.8 84.5 12 Janet 62.5 112.5 15 Jeffrey 62.5 84.0 13 John 59.0 99.5 12 Joyce 51.3 50.5 11 Judy 64.3 90.0 14 Louise 56.3 77.0 12 Mary 66.5 112.0 15 Philip 72.0 150.0 16 Robert 64.8 128.0 12 Ronald 67.0 133.0 15 Thomas 57.5 85.0 11 William 66.5 112.0 15 ;run;

proc reg data=class ;model Height=Age;run;proc reg data=class outest=est noprint;model Height=Age;run;

proc print data=est;run;[edit]

Example 4

Setting up arbitrary groups based on the students' names data class2;set class;group=1;if substr(Name,1,1)='J' then group=2;run;

* Sorting is required before BY statement processing;proc sort data=class2;by group;run;

proc reg data=class2;model Height=Age;by group;run;[edit]

Example 4a

Illustrating an efficient concise form for outputing several regression models' results proc reg data=class2 outest=est2 noprint;

Page 32: 81646619 Base Sas Certification Exercise

model Height=Age;by group;run;

proc print data=est2;run;[edit]

Example 5

Illustrating using PROC REG to generate other output; the residuals from a regression proc reg data=class2;model height=age;output out=DS1 r=george;run; proc print data=DS1;run;

proc sort data=DS1;by descending george ;run;

proc print data=DS1;var name age height george;run;

SAS Certification Examples(part 2)

From BingWiki

Jump to: navigation, search<Back to Part 1, the first 5 sessions Back to SAS Certification Examples and Exercises (Part 2)

Contents

[hide]

• 1 Session 6 o 1.1 Example 1 o 1.2 Example 2 o 1.3 Example 3 o 1.4 Example 4

Page 33: 81646619 Base Sas Certification Exercise

o 1.5 Example 4a o 1.6 Example 5 o 1.7 Closing examples

• 2 Session 7 o 2.1 In class o 2.2 Some similar functions,formats and informats

• 3 Session 8 • 4 Session 9

o 4.1 Example 1 o 4.2 Example 2 o 4.3 Example 3 o 4.4 Example 3A o 4.5 Example 4

• 5 Session 10 o 5.1 Example 1

• 6 Example 2 • 7 Examples for Model Procedure

o 7.1 A second example for parabolic curve [edit]

Session 6

[edit]

Example 1

data test;file 'c:\Temp\myfile.txt';x=10; y=20;put x;put y;output;x=3; y=36;put x;put y;put 'All done.';run;

Try putting a * in front of the file statement. Run the code clip again and look what's in the LOG. After making a dataset in SAS, it becomes a temporary .sas7bdat file in a WORK library that is cleared when you close the SAS session. data test;x=10; y=20;output;run;Before you close SAS you can simple read it by using a set statement.

Page 34: 81646619 Base Sas Certification Exercise

Here's an example of reading a plain text file data testds;infile 'c:\Temp\myfile.txt';input x;run;

proc print data=testds;run;[edit]

Example 2

Strings data strings1;infile 'c:\Temp\strings.txt';input id month $ grade $1. correct total;run;

proc print data=strings1;run;The $1. is an INformat. An informat always has a . (dot) in it.

Without an informat specification on the INPUT statement SAS may have some difficulty determining what length to make the placeholder for the textual information in a column. data strings1;infile 'c:\Temp\strings.txt';input id month $ grade $ correct total;run;

proc print data=strings1;run;To assist SAS with correctly jumping to a column where we expect certain data to reside on each record/row we use pointer control (using the @ sign on the INPUT statement). data justyr;infile 'c:\Temp\strings.txt';input @10 yr @13 grade $1. @15 correct total;run;

proc print data=justyr;run;[edit]

Example 3

Using Informats to do more. data strings2;input id month $ grade $upcase1. correct total major $20.;cards;101 10-2006 A 12 14 Economics

Page 35: 81646619 Base Sas Certification Exercise

101 11-2006 A 15 15 Econ101 12-2006 B 15 20 economics101 1-2007 a 15 15 econ102 10-2006 c 10 14 Psychology102 12-2006 C 12 20 Psych102 01-2007 B 13 15 PSYCH103 10-2006 a 14 14 Econ103 11-2006 B 12 15 Econ103 12-2006 B 16 20 Econ104 01-2007 A 15 15 Decker School of Nursing;run;

proc print data=strings2;run;[edit]

Example 4

Using common string functions. data str3;set strings2;m=substr(month,1,2);maj=substr(major,1,4);l=length(major);lenm=length(month);run;

data str4;set strings2;maj=upcase(substr(major,1,4));run;[edit]

Example 4a

A short practical use of converting everything to upper case and using a 'subsetting IF' statement. data econ;set str4;if (maj='ECON');run;

proc means data=econ;var correct;run;

proc print data=econ;run;

Other functions (acting on character strings) /*

Page 36: 81646619 Base Sas Certification Exercise

indexanyloweranyupper if 'a'='A' then do; end;anyspace if upcase('a')=upcase('A') then do; end;*/[edit]

Example 5

INformats for numbers. data numbers;input n 4.1 @6 n2 ;cards;01234567891089128273849999996666 103;run;

proc print data=numbers;run;[edit]

Closing examples

data stringok;input @21 majorcap $upcase4.; cards; 101 10-2006 A 12 14 Economics101 11-2006 A 15 15 Econ101 12-2006 B 15 20 economics101 1-2007 a 15 15 econ102 10-2006 c 10 14 Psychology102 12-2006 C 12 20 Psych102 01-2007 B 13 15 PSYCH103 10-2006 a 14 14 Econ103 11-2006 B 12 15 Econ103 12-2006 B 16 20 Econ104 01-2007 A 15 15 Decker School of Nursing;run;

proc print data=stringok;run;

data stringweird;input @21 majorcap $revers4.; cards; 101 10-2006 A 12 14 Economics101 11-2006 A 15 15 Econ101 12-2006 B 15 20 economics101 1-2007 a 15 15 econ

Page 37: 81646619 Base Sas Certification Exercise

102 10-2006 c 10 14 Psychology102 12-2006 C 12 20 Psych102 01-2007 B 13 15 PSYCH103 10-2006 a 14 14 Econ103 11-2006 B 12 15 Econ103 12-2006 B 16 20 Econ104 01-2007 A 15 15 Decker School of Nursing;run;

proc print data=stringweird;run;

[edit]

Session 7

No data for today. We'll use datasets in the SASHELP library, or files that we explicitly create in class. Be sure to look at the references (listed at 'Essential Readings') for functions and functions by category (to find those listed for SAS Dates and Times). We'll be speaking about date/time related Formats, and Informats today as well. To look at what's possible with SAS graphics the SAS/Graph overview is an excellent place to start. [edit]

In class

data test;x=today();x1=today()+1;x2='31DEC1960'D ;x3='02JAN1961'D ;x4='02JAN1961'D +0;x5='02JAN1961'D *1;run;

proc print data=test;run;

proc contents data=test;run;

proc print data=test;format x1 year4. ;format x3 JULDAY3. ;format x4 DATE9. ;run;

data test2;set test;

Page 38: 81646619 Base Sas Certification Exercise

format x1 MMDDYYS8. ;format x2 WEEKDATE23. ;format x3 WEEKDAY1. ;run;

proc print data=test2;run;

proc contents data=sashelp.air;run;proc print data=sashelp.air (obs=10);format date WEEKDATE23. ;var date;run;

*date_. monyy. ddmmyy__. WEEKDATE__. WEEKDAY1. JULDAY3. YEAR4. ;

data test3;set sashelp.air;day=day(date);mo=month(date);run;

data test4;dob='07JUL1980'D ;t=today();*yearsold=intck(year,dob,t);yrsapprox=(t-dob)/365;run;proc print data=test4;run;

* DATDIF INTCK;data test5;m=6;d=3;y=1960;sasda=mdy(m,d,y);run;

proc print data=test5;format sasda date9.;run;

* AIR CITIYR CITIDAY;

data class2;set sashelp.class;run;

ods html;ods graphics on;proc reg data=class2;model height=weight;run;

Page 39: 81646619 Base Sas Certification Exercise

[edit]

Some similar functions,formats and informats

Functions Formats Informats

Date Function DATEw Format DATEw. Informat

data test;x=DATE();run;

data test;input x y z;cards;1 21 81 2 11 84;run;data test1;set test;birthday=mdy(x,y,z);format birthday date9.;run;

data test;input x date9.;cards;16mar9901nov06;run;

MDY Function MMDDYYw. FormatYYMMDDw. Informat

data test;input x y z;cards;1 21 812 11 84;run;data test1;set test;birthday=mdy(x,y,z);run;

data test;input x y z;cards;1 21 812 11 84;run;data test1;set test;birthday=mdy(x,y,z);format birthday mmddyy10.;run;

data test;input x yymmdd10.;cards;051221060808;run;

[edit]

Session 8

Test score data 101 57102 52104 87105 69106 62107 75108 41109 41110 79111 25

Page 40: 81646619 Base Sas Certification Exercise

119 36118 82114 41[edit]

Session 9

[edit]

Example 1

for arrays Baseball YANKS,0,0,0,0,1,2,0,0,1METS, 0,0,0,0,0,1,0,1,1[edit]

Example 2

Soup data North,Johnson City,CHICKRICE,CHICKRICE,CHICKRICE,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKGARL,CHICKGARL,CHICKGARL,POTATOGARL,POTATOGARL,TOMATO,TOMATO,TOMATO,TOMATO,TOMATO,TOMATO,TOMATO,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,MINESTRONE,MINESTRONE,LENTIL,MEATPAST,BEEFBAR,ITALIANWED,CLAMCHOWNE,CLAMCHOWFF,SAUSPEPP,SAUSPEPP,BEANHAM,BEANHAM,BEANHAM,SPLITPEAHAM,SPLITPEAHAM,SPLITPEAHAM,,,,,,,Main,Binghamton,CHICKVEG,CHICKRICE,CHICKRICE,CHICKRICE,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKGARL,CHICKGARL,CHICKGARL,POTATOGARL,POTATOGARL,TOMATO,TOMATO,TOMATO,TOMATO,TOMATO,TOMATO,TOMATO,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,MEATPAST,BEEFBAR,ITALIANWED,CLAMCHOWNE,CLAMCHOWNE,SAUSPEPP,SAUSPEPP,SAUSPEPP,SAUSPEPP,BEANHAM,BEANHAM,BEANHAM,SPLITPEAHAM,SPLITPEAHAM,,,,,,,,,North,Endwell,CHICKMEX,CHICKMEX,CHICKMEX,CHICKMEX,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKRICE,CHICKRICE,CHICKALF,CHICKALF,CHICKALF,CHICKALF,CHICKALF,CHICKPENNE,CHICKPENNE,CHICKPENNE,CHICKPENNE,CHICKPENNE,CHICKVEG,CHICKVEGMED,CHICKVEGMED,CHEESERAV,VEGMED,VEGMED,VEGMED,VEGMED,POTATOGARL,POTATOGARL,TOMATO,TOMATO,TOMATO,TOMATO,MINESTRONE,POTATOBROCC,POTATOBROCC,POTATOBROCC,LENTIL,MEATPAST,MEATPAST,BEEFVEG,ITALIANWED,ITALIANWED,ITALIANWED,CLAMCHOWNE,SAUSPEPP,SAUSPEPP,SAUSPEPP,BEANHAM,BEANHAM,BEANHAM,BEANHAM,SPLITPEAHAM,Main,Vestal,CHICKMEX,CHICKMEX,CHICKMEX,CHICKMEX,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKRICE,CHICKRICE,CHICKALF,CHICKALF,CHICKALF,CHICKALF,CHICKALF,CHICKPENNE,CHICKPENNE,CHICKPENNE,CHICKPENNE,CHICKPENNE,CHICKVEG,CHICKVEGMED,CHICKVEGMED,CHEESERAV,VEGMED,VEGMED,VEGMED,VEGMED,POTATOGARL,POTATOGARL,TOMATO,TOMATO,TOMATO,TOMATO,MINESTRONE,POTATOBROCC,POTATOBROCC,POTATOBROCC,LENTIL,MEATPA

Page 41: 81646619 Base Sas Certification Exercise

ST,MEATPAST,MINESTRONE,MINESTRONE,MINESTRONE,TOMATO,TOMATO,CLAMCHOWNE,CLAMCHOWNE,CLAMCHOWFF,CLAMCHOWFF,BEANHAM,BEANHAM,BEANHAM,BEANHAM,SPLITPEAHAMJenson,Binghamton,CHICKRICE,CHICKRICE,CHICKRICE,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKGARL,CHICKGARL,CHICKGARL,POTATOGARL,POTATOGARL,TOMATO,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,MINESTRONE,MINESTRONE,LENTIL,MEATPAST,BEEFBAR,ITALIANWED,CLAMCHOWNE,CLAMCHOWFF,SAUSPEPP,SAUSPEPP,BEANHAM,BEANHAM,BEANHAM,BEANHAM,SPLITPEAHAM,BEANHAM,BEANHAM,BEANHAM,BEANHAM,SPLITPEAHAM,,,,,,,,,Court,Binghamton,CHICKVEG,CHICKRICE,CHICKRICE,CHICKRICE,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKGARL,CHICKGARL,CHICKGARL,POTATOGARL,POTATOGARL,CHICKWILD,CHICKWILD,CHICKWILD,CHEESERAV,CHEESERAV,CHEESERAV,MINESTRONE,MINESTRONE,MINESTRONE,MINESTRONE,MINESTRONE,POTATOBROCC,POTATOBROCC,POTATOBROCC,LENTIL,LENTIL,LENTIL,LENTIL,LENTIL,MEATPAST,MEATPAST,BEEFBAR,BEEFBAR,BEEFBAR,BEEFBAR,CLAMCHOWNE,CLAMCHOWNE,BEANHAM,BEANHAM,BEANHAM,BEANHAM,SPLITPEAHAM,,,,Front,Binghamton,LENTIL,LENTIL,LENTIL,BEEFBAR,BEEFBAR,VEGMED,VEGMED,VEGMED,SAUSPEPP,SAUSPEPP,SAUSPEPP,SAUSPEPP,VEGMED,ITALIANWED,CLAMCHOWNE,CLAMCHOWFF,BEANHAM,BEANHAM,SPLITPEAHAM,CHICKNOOD,CHICKRICE,CHICKALF,CHICKWILD,CHICKWILD,CHICKPENNE,MEATPAST,MEATPAST,MEATPAST,MINESTRONE,CHICKALF,VEGMED,VEGMED,POTATOGARL,POTATOGARL,POTATOGARL,,,,,,,,,,,,,,,,,,,,,,Main,Endicott,CHICKNOOD,CHICKNOOD,CHICKVEGMED,CHICKNOOD,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKGARL,CHICKGARL,CHICKGARL,POTATOGARL,POTATOGARL,CHICKWILD,CHICKWILD,CHICKWILD,CHEESERAV,CHEESERAV,CHEESERAV,MINESTRONE,MINESTRONE,MINESTRONE,MINESTRONE,MINESTRONE,POTATOBROCC,POTATOBROCC,POTATOBROCC,LENTIL,LENTIL,LENTIL,LENTIL,LENTIL,TOMATO,TOMATO,MEATPAST,MEATPAST,BEEFBAR,BEEFBAR,BEEFBAR,BEEFBAR,CLAMCHOWFF,CLAMCHOWFF,CLAMCHOWNE,CLAMCHOWNE,BEANHAM,BEANHAM,BEANHAM,BEANHAM,SPLITPEAHAM,,,,,,,,Grand Ave,Johnson City,CHICKRICE,CHICKRICE,CHICKRICE,CHICKRICE,CHICKRICE,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKGARL,CHICKGARL,CHICKGARL,POTATOGARL,POTATOGARL,CHICKWILD,CHICKWILD,CHICKWILD,CHEESERAV,CHEESERAV,CHEESERAV,MINESTRONE,MINESTRONE,MINESTRONE,MINESTRONE,MINESTRONE,POTATOBROCC,POTATOBROCC,POTATOBROCC,LENTIL,LENTIL,LENTIL,LENTIL,LENTIL,MEATPAST,MEATPAST,BEEFBAR,BEEFBAR,BEEFBAR,BEEFBAR,CLAMCHOWNE,CLAMCHOWNE,BEANHAM,BEANHAM,BEANHAM,BEANHAM,SPLITPEAHAM,,,,,,,,,,,Floral,Johnson City,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKRICE,CHICKRICE,CHICKALF,CHICKALF,CHICKALF,CHICKALF,CHICKALF,CHICKPENNE,CHICKPENNE,CHICKPENNE,CHICKPENNE,CHICKPENNE,CHICKVEG,CHICKVEGMED,CHICKVEGMED,CHEESERAV,VEGMED,VEGMED,VEGMED,VEGMED,POTATOGARL,POTATOGARL,TOMATO,TOMATO,TOMATO,TOMATO,MINESTRONE,POTATOBROCC,POTATOBROCC,POTATOBROCC,LENTIL,MEATPAST,MEATPAST,MINESTRONE,MINESTRONE,MINESTRONE,TOMATO,TOMATO,CLAMCHOWNE,CLAMCHOWNE,TOMATO,,,,,,,,,,,,Floral,Binghamton,CHICKVEG,CHICKRICE,CHICKRICE,CHICKRICE,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKGARL,CHICKGARL,CHICKGARL,POTATOGARL,POTATOGARL,TOMATO,TOMATO,TOMATO,TOMATO,TOMATO,TOMATO,TOMATO,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,CHICKWILD,MEATPAST,ITALIANWED,CLAMCHOWNE,CLAMCHOWNE,SAUSPEPP,SAUSPEPP,SAUSPEPP,SAUSPEPP,BEANHAM,BEANHAM,BEANHAM,SPLITPEAHAM,SPLITPEAHAM,,,,,,,,,,

Page 42: 81646619 Base Sas Certification Exercise

Vestal,Binghamton,CHICKMEX,CHICKMEX,CHICKMEX,CHICKMEX,CHICKMEX,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKRICE,CHICKRICE,CHICKALF,CHICKALF,CHICKALF,CHICKALF,CHICKPENNE,CHICKPENNE,CHICKPENNE,CHICKPENNE,CHICKPENNE,CHICKVEG,CHICKVEGMED,CHICKVEGMED,CHEESERAV,VEGMED,VEGMED,VEGMED,VEGMED,POTATOGARL,POTATOGARL,TOMATO,TOMATO,TOMATO,TOMATO,MINESTRONE,POTATOBROCC,POTATOBROCC,LENTIL,MEATPAST,MEATPAST,MINESTRONE,MINESTRONE,MINESTRONE,TOMATO,TOMATO,CLAMCHOWNE,CLAMCHOWNE,CLAMCHOWNE,CLAMCHOWNE,BEANHAM,BEANHAM,BEANHAM,BEANHAM,SPLITPEAHAM,West,Endwell,CHICKNOOD,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKGARL,CHICKGARL,CHICKGARL,POTATOGARL,POTATOGARL,CHICKWILD,CHICKWILD,CHICKWILD,CHEESERAV,CHEESERAV,CHEESERAV,MINESTRONE,MINESTRONE,MINESTRONE,MINESTRONE,MINESTRONE,POTATOBROCC,POTATOBROCC,POTATOBROCC,LENTIL,LENTIL,LENTIL,LENTIL,LENTIL,TOMATO,TOMATO,MEATPAST,MEATPAST,BEEFBAR,BEEFBAR,BEEFBAR,BEEFBAR,CLAMCHOWFF,CLAMCHOWFF,CLAMCHOWNE,CLAMCHOWNE,BEANHAM,BEANHAM,BEANHAM,BEANHAM,SPLITPEAHAM,,,,,,,,,,,First,Binghamton,CHICKNOOD,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKVEGMED,CHICKGARL,CHICKGARL,CHICKGARL,POTATOGARL,POTATOGARL,CHICKWILD,CHICKWILD,CHICKWILD,CHEESERAV,CHEESERAV,CHEESERAV,MINESTRONE,MINESTRONE,MINESTRONE,MINESTRONE,MINESTRONE,POTATOBROCC,POTATOBROCC,POTATOBROCC,LENTIL,LENTIL,LENTIL,LENTIL,LENTIL,MEATPAST,MEATPAST,MEATPAST,MEATPAST,BEEFBAR,BEEFBAR,BEEFBAR,BEEFBAR,CLAMCHOWFF,CLAMCHOWFF,CLAMCHOWNE,BEANHAM,BEANHAM,BEANHAM,BEANHAM,SPLITPEAHAM,TOMATO,,,,,,,,,,,Farr Ave,Vestal,VEGMED,VEGMED,VEGMED,TOMATO,TOMATO,CHICKPENNE,CHICKPENNE,CHICKPENNE,CHICKALF,CHICKALF,CHICKALF,CHICKALF,CHICKMEX,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,POTATOGARL,LENTIL,LENTIL,LENTIL,LENTIL,LENTIL,BEEFBAR,BEEFBAR,BEEFVEG,BEEFVEG,BEEFVEG,BEEFVEG,ITALIANWED,ITALIANWED,ITALIANWED,CLAMCHOWNE,CLAMCHOWNE,CLAMCHOWNE,CLAMCHOWNE,CLAMCHOWNE,CLAMCHOWFF,CLAMCHOWFF,CLAMCHOWFF,CLAMCHOWFF,BEANHAM,BEANHAM,SAUSPEPP,,,,,,,,,,Clifford,Binghamton,CLAMCHOWNE,CLAMCHOWNE,CLAMCHOWNE,SAUSPEPP,BEANHAM,SPLITPEAHAM,CHICKMEX,CHICKMEX,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKRICE,CHICKRICE,CHICKRICE,CHICKRICE,CHICKRICE,CHICKWILD,CHICKWILD,CHICKPENNE,CHEESERAV,CHEESERAV,CHEESERAV,VEGMED,POTATOGARL,MINESTRONE,MINESTRONE,LENTIL,LENTIL,LENTIL,MEATPAST,BEEFBAR,,,,,,,,,,,,,,,,,,,,,,,,,Maxwell,Johnson City,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKVEG,CHICKVEG,CHICKGARL,CHICKGARL,CHEESERAV,CHEESERAV,CHEESERAV,VEGMED,VEGMED,VEGMED,VEGMED,TOMATO,TOMATO,TOMATO,MINESTRONE,MINESTRONE,POTATOBROCC,LENTIL,LENTIL,MEATPAST,BEEFBAR,BEEFBAR,BEEFBAR,BEEFBAR,BEEFVEG,BEEFVEG,BEEFVEG,BEEFVEG,BEEFVEG,CLAMCHOWNE,CLAMCHOWNE,CLAMCHOWNE,CLAMCHOWNE,CLAMCHOWFF,SAUSPEPP,SAUSPEPP,BEANHAM,BEANHAM,BEANHAM,SPLITPEAHAM,,Riverside Drive,Binghamton,CHICKNOOD,CHICKVEG,CHICKVEG,CHICKGARL,CHICKGARL,CHEESERAV,CHEESERAV,CHEESERAV,VEGMED,VEGMED,VEGMED,VEGMED,TOMATO,TOMATO,TOMATO,TOMATO,TOMATO,MINESTRONE,MINESTRONE,POTATOBROCC,LENTIL,LENTIL,MEATPAST,BEEFBAR,BEEFBAR,BEEFBAR,BEEFBAR,BEEFVEG,BEEFVEG,BEEFVEG,BEEFVEG,BEEFVEG,CLAMCHOWNE,CLAMCHOWNE,CLAMCHOWNE,CLAMCHOWNE,CLAMCHOWFF,SAUSPEPP,SAUSPEPP,BEANHAM,BEANHAM,BEANHAM,SPLITPEAHAM,SPLITPEAHAM,SPLITPEAHAMOak,Endicott,CHICKNOOD,CHICKNOOD,CHICKNOOD,CHICKVEG,CHICKVEG,CHICKGARL,CHICKGARL,CHEESERAV,CHEESERAV,CHEESERAV,VEGMED,VEGMED,VEGMED,VEGMED,TOMATO,TOMATO,TOMATO,MINESTRONE,MINESTRONE,POTATOBROCC,LENTIL,LENTIL,MEATPAST,BEEFBAR,BEEFBAR,BEEFBAR,BEEFBAR,BEEFVEG,BEEFVEG,BEEFVEG,BE

Page 43: 81646619 Base Sas Certification Exercise

EFVEG,BEEFVEG,CLAMCHOWNE,CLAMCHOWNE,CLAMCHOWNE,CLAMCHOWNE,CLAMCHOWNE,SAUSPEPP,SAUSPEPP,BEANHAM,BEANHAM,BEANHAM,,,[edit]

Example 3

for PROC TRANSPOSE x,y,z1,2,34,5,67,8,910,11,12[edit]

Example 3A

id,x,y,z101,1,2,3101,4,5,6101,7,8,9101,10,11,12102,10000,20000,30000102,40000,50000,60000102,70000,80000,90000102,99999,99999,99999[edit]

Example 4

id date returns 101 1/1/04 8.1 102 2/1/04 7.2 103 3/1/04 7.3 104 4/1/04 7.9 105 5/1/04 13.7 106 6/1/04 14.6 107 7/1/04 14.8 108 8/1/04 13.7 109 9/1/04 13.9 110 10/1/04 15.1 111 11/1/04 14.9 112 12/1/04 13.7 113 1/1/05 14.5 114 2/1/05 20.2 115 3/1/05 19 116 4/1/05 21 117 5/1/05 26.1 118 6/1/05 26.2 119 7/1/05 25.5 120 8/1/05 26.8 121 9/1/05 25.4 122 10/1/05 26.4

Page 44: 81646619 Base Sas Certification Exercise

123 11/1/05 25.8 124 12/1/05 26.3 125 1/1/06 26.4 126 2/1/06 32.7 127 3/1/06 31.9 128 4/1/06 32.3 129 5/1/06 31.6 130 6/1/06 37.8 131 7/1/06 39 132 8/1/06 37 133 9/1/06 37.9 134 10/1/06 37.5 135 11/1/06 38.9 136 12/1/06 44.2[edit]

Session 10

[edit]

Example 1

How to transpose the data? The example from online documentation. data score; input Student $9. StudentID $ Test1 Test2 Final; datalines;Capalleti 0545 94 91 87Dubose 1252 51 65 91Engles 1167 95 97 97Grant 1230 63 75 80Krupski 2527 80 76 71Lundsford 4860 92 40 86McBane 0674 75 78 72;proc transpose data=score out=scoretran;run;proc print data=scoretran;run;[edit]

Example 2

Logistic Data 1 ACT 3 NO 2 ACT 3 YES 4 ACT 3 YES 6 ACT 6 YES 7 ACT 15 NO 10 ACT 6 YES 11 ACT 6 YES 14 ACT 6 YES 15 ACT 15 NO 17 ACT 15 NO 20 ACT 12 NO 21 ACT 18 NO 22 ACT 6 YES 25 ACT 15 NO 26 ACT 6 YES 28 ACT 15 NO 29 ACT 12 YES 32 ACT 9 NO 33 ACT 6 YES 36 ACT 6 NO 39 ACT 6 NO 42 ACT 6 NO 44 ACT 3 YES 46 ACT 18 NO

Page 45: 81646619 Base Sas Certification Exercise

49 ACT 9 NO 50 ACT 12 YES 52 ACT 6 NO 54 ACT 9 YES 56 ACT 9 YES 58 ACT 3 NO 60 ACT 9 YES 62 ACT 12 NO 63 ACT 12 NO 66 ACT 3 NO 67 ACT 12 NO 69 ACT 12 NO 71 ACT 12 NO 73 ACT 9 YES 74 ACT 6 YES 77 ACT 12 NO 79 ACT 6 NO 81 ACT 15 YES 83 ACT 9 NO 85 ACT 3 YES 88 ACT 9 NO 90 ACT 9 NO 92 ACT 9 NO 94 ACT 9 NO 95 ACT 9 YES 98 ACT 12 YES 99 ACT 3 YES102 ACT 6 YES 3 PBO 9 YES 5 PBO 3 NO 8 PBO 12 YES 9 PBO 3 YES 12 PBO 3 YES 13 PBO 15 YES 16 PBO 9 YES 18 PBO 12 YES 19 PBO 3 YES 23 PBO 9 YES 24 PBO 15 YES 27 PBO 9 YES 30 PBO 6 YES 31 PBO 9 YES 34 PBO 6 YES 35 PBO 12 NO 37 PBO 9 NO 38 PBO 15 NO 40 PBO 15 YES 41 PBO 9 NO 43 PBO 9 NO 45 PBO 12 YES 47 PBO 3 YES 48 PBO 6 YES 51 PBO 6 YES 53 PBO 12 NO 55 PBO 12 NO 57 PBO 12 YES 59 PBO 3 YES 61 PBO 12 YES 64 PBO 3 YES 65 PBO 12 YES 68 PBO 6 YES 70 PBO 6 YES 72 PBO 9 YES 75 PBO 15 NO 76 PBO 15 NO 78 PBO 12 NO 80 PBO 9 NO 82 PBO 12 NO 84 PBO 15 NO 86 PBO 18 YES 87 PBO 12 NO 89 PBO 15 YES 91 PBO 15 NO 93 PBO 15 NO 96 PBO 18 NO 97 PBO 18 YES 100 PBO 18 NO 101 PBO 18 NO[edit]

Examples for Model Procedure

pop year 3.929 1790 5.308 1800 7.239 1810 9.638 1820 12.866 1830 17.069 1840 23.191 1850 31.443 1860 39.818 1870 50.155 1880 62.947 1890 75.994 1900 91.972 1910 105.71 1920122.775 1930131.669 1940151.325 1950179.323 1960203.211 1970226.542 1980 248.71 1990as a csv pop,year

Page 46: 81646619 Base Sas Certification Exercise

3.929,17905.308,18007.239,18109.638,182012.866,183017.069,184023.191,185031.443,186039.818,187050.155,188062.947,189075.994,190091.972,1910105.71,1920122.775,1930131.669,1940151.325,1950179.323,1960203.211,1970226.542,1980248.71,1990[edit]

A second example for parabolic curve

x,y-3,37.4000-3,37.0000-3,36.8000-2,26.2000-2,26.1000-2,26.0000-2,26.0000-1,16.5000-1,16.9000-1,17.0000-1,17.50000,9.90000,10.00000,9.50000,9.90001,4.90001,5.20001,4.50001,4.80002,2.20002,1.50002,1.80002,2.30003,1.40003,0.80004,1.50004,2.50004,2.5000

Page 47: 81646619 Base Sas Certification Exercise