Friday, 2 October 2015

Ch 20 - Generating High-Quality Graphics

Chapter 20(Generating High-Quality Graphics)


This chapter introduces some basic concepts behind SAS/GRAPH software. Here you
will see how to create simple bar charts, scatter plots, and line graphs. There are many
excellent books and manuals available from SAS Press.

Chapter#20 and Problem#3

Using the SAS data set Bicycles, produce a vertical bar chart showing the
distribution of Total Sales (TotalSales). Use midpoints of 0 to 12,000, with intervals
of 2,000.

Solution:

Result:


Chapter#20 and Problem#9

Using the SAS data set Stocks, produce a scatter plot of Price versus Date. Use the
dot as the plotting symbol and connect the dots with a smooth line.

Solution:

Result:







Back to Index

Ch19 - Output Delivery System

Chapter 19 (Output Delivery System)



One of the most important changes in SAS, the introduction of Output Delivery System called as ODS. Each SAS procedure produce its unique output . This output was difficult to incorporate into other documents, such as Microsoft Office Word orMicrosoft Office PowerPoint.The Output Delivery System changed all that. Now each SAS procedure creates outputobjects that can be sent to such destinations as HTML, RTF, PDF, and SAS data sets.
 Not only can you send your SAS output to all of these formats, you can, if you are brave enough, customize the output’s fonts, colors, size, and
layout.

Chapter#19 and Problem#1

Run the following program, sending the output to an HTML file. Issue the
appropriate commands to prevent SAS from creating a listing file. See Chapter 16,
Problem 2, for the note about creating formats for this data set.
title "Sending Output to an HTML File";
proc print data=learn.college(obs=8) noobs;
run;
proc means data=learn.college n mean maxdec=2;
var GPA ClassRank;
run;

Solution:
Result:


Chapter#19 and Problem#3

Run the same two procedures as shown in Problem 1, except use the JOURNAL (or

FANCYPRINTER) style instead of the default style.

Solution:

Result:









Ch18 - Creating Tabular Reports

Chapter 18(Creating Tabular Reports)


In this chapter, I am  going to generate the report in tabular form. that displaying frequencies, percentages, and descriptive statistics (such as sums and means) broken by one or more CLASS variables.
Chapter#18 and Problem#1


All the problems, except Problem 10, use the SAS data set College.
Note: Data set College has permanent formats for Gender, SchoolSize, and Scholarship.
Either make this format catalog available to SAS (see Chapter 5), run the PROC
FORMAT statements here, or use the system option NOFMTERR (no format
error) that allows you to access SAS data sets that have permanent user-defined
formats without causing an error.
proc format;
value $yesno 'Y','1' = 'Yes'
'N','0' = 'No'
' ' = 'Not Given';
value $size 'S' = 'Small'
'M' = 'Medium'
'L' = 'Large'
' ' = 'Missing';
value $gender 'F' = 'Female'
'M' = 'Male'
' ' = 'Not Given';
run;
For each problem, you need to write the appropriate PROC TABULATE statements to
produce the given table.

Produce the following table. Note that the last row in the table represents all subjects.
Demographics from COLLEGE Data Set-

Solution:

Result:


Learning:
1# In this  problem, I have learnt what happened when we use proc tabulate data step 
2# proc tabulate uses a class statement to allow you to specify variables that represent category (often) character variable where we want to compute frequencies or percentage.
3# In this problem, gender, scholarship and schoolsize taken as a class variable and tables statement specify the appearance.
4# Any variable listed in a TABLE statement must be listed in a CLASS statement or a VAR statement (to be discussed shortly).

Chapter#18 and Problem #3

Produce the following table. Note that the ALL column has been renamed Total and
Gender has been formatted.
Demographics from COLLEGE Data Set

Solution:

Result:

Learning:
1# In this problem, I have broken down the school size in one or more variable of the class variable such as  gender or school size.
2# Here, I have combined frequencies and descriptive statistics in single table. 
3# School size broken into class gender, scholarship and school size.



Ch 17 - Counting Frequencies

Chapter 17(Counting Frequencies)


In this chapter I will learn how to generate frequency table with the help proc freq. Proc freq use for both character as well as numeric variable in one-way, two-way, and three-way. I can also use proc freq to create output data stes containing counts and percentage. We can also measure various statistics such as chi-square, odds ratio and relative risk 

Chapter#17 and Problem#1

Using the SAS data set Blood, generate one-way frequencies for the variables

Gender, BloodType, and AgeGroup. Use the appropriate options to omit the
cumulative statistics and percentages.

Solution:



Result:

Learning:
1# In this problem I have learnt how to generate frequency table 
2# I have used tables statement for compute frequency every variable in dataset
3# I have used nocum and noperecent that indicates that i do not want cumulative frequency as well as percentage.

Chapter#17 and Problem #3

Using the data set Blood, produce frequencies for the variable Chol (cholesterol).
Use a format to group the frequencies into three groups: low to 200 (normal), 201
and higher (high), and missing. Run PROC FREQ twice, once using the MISSING
option, and once without. Compare the percentages in both listings.

Solution:
Result:

Learning:
1# In this problem, I have proc format for formatting for labelling the output. it improves the appearance of the report when we used a format to label these values. 
2# proc freq used because I want to compute frequencies on formatted values, we can also use format to group values together into larger categories.


Ch16 - Summarizing Your Data

Chapter#16: (Summarizing Your Data)


In this chapter I am going to the use of proc means and proc summary to generate summary reports. Summary consists several statistics part like sum and means of numeric variables. However, these procedures are much more versatile and can be used to create summary
data sets that can then be analysed with more data or proc steps.


Chapter#16 and Problem#1:
Using the SAS data set College, compute the mean, median, minimum, and
maximum and the number of both missing and non-missing values for the variables

ClassRank and GPA. Report the statistics to two decimal places.

Solution:



Result:

Learning:
1# I have used title statement that gives the title for the output
2# how to use proc means to generate reports
3# I have used to variable that is ClassRank and GPA
4# for the customization I have used N and N miss
5# in code I used maxdec=2  that shows the values goes upto two decimal point

Chapter#16 and Problem #3
Using the SAS data set College, report the mean and median GPA and ClassRank

broken down by school size (SchoolSize). Do this twice, once using a BY statement,
and once using a CLASS statement.

Solution:
Result:

Learning:
1# when we want to see descriptive statistics for each level of another variable then we use by statement.
2# when we use this first of all we have to sort the data set by the same variable or variables you list in by statement
3#  here i sorted the data set by school size thats why you can see in result display output by Missing, Small, Large school size.
4# the same thing i have done with the use of class statement that shows the same result


Chapter#16 and Problem#5
Using the SAS data set College, report the mean GPA for the following categories of

ClassRank: 0–50 = bottom half, 51–74 = 3rd quartile, and 75 to 100 = top
quarter. Do this by creating an appropriate format. Do not use a DATA step.

Solution:

Result:

Learning:
1# One very nice feature of using a CLASS statement (besides not having to sort your data)is that SAS uses formatted values of the CLASS variable(s).
2# Here I have used proc format statement to the procedure and changing how the class variable groups your data.
3# Like here I have used for Bottom Half, Third Quartile and Top Quartile and formatting is done on the basis of ClassRank.




SAS Index

SAS 2nd Practice Problem

Chapter#16: (Summarizing Your Data)

In this chapter I am going to the use of proc means and proc summary to generate summary reports. Summary consists several statistics part like sum and means of numeric variables. However, these procedures are much more versatile and can be used to create summary
data sets that can then be analysed with more data or proc steps.


Chapter#16 and Problem#1:
Using the SAS data set College, compute the mean, median, minimum, and
maximum and the number of both missing and non-missing values for the variables

ClassRank and GPA. Report the statistics to two decimal places.

Solution:


 Result:

Learning:
1# I have used title statement that gives the title for the output
2# how to use proc means to generate reports
3# I have used to variable that is ClassRank and GPA
4# for the customization I have used N and N miss
5# in code I used maxdec=2  that shows the values goes upto two decimal point

Chapter#16 and Problem #3
Using the SAS data set College, report the mean and median GPA and ClassRank

broken down by school size (SchoolSize). Do this twice, once using a BY statement,
and once using a CLASS statement.

Solution:
Result:

Learning:
1# when we want to see descriptive statistics for each level of another variable then we use by statement.
2# when we use this first of all we have to sort the data set by the same variable or variables you list in by statement
3#  here i sorted the data set by school size thats why you can see in result display output by Missing, Small, Large school size.
4# the same thing i have done with the use of class statement that shows the same result


Chapter#16 and Problem#5
Using the SAS data set College, report the mean GPA for the following categories of

ClassRank: 0–50 = bottom half, 51–74 = 3rd quartile, and 75 to 100 = top
quarter. Do this by creating an appropriate format. Do not use a DATA step.

Solution:

Result:

Learning:
1# One very nice feature of using a CLASS statement (besides not having to sort your data)is that SAS uses formatted values of the CLASS variable(s).
2# Here I have used proc format statement to the procedure and changing how the class variable groups your data.
3# Like here I have used for Bottom Half, Third Quartile and Top Quartile and formatting is done on the basis of ClassRank.

Chapter 17(Counting Frequencies)

In this chapter I will learn how to generate frequency table with the help proc freq. Proc freq use for both character as well as numeric variable in one-way, two-way, and three-way. I can also use proc freq to create output data stes containing counts and percentage. We can also measure various statistics such as chi-square, odds ratio and relative risk 

Chapter#17 and Problem#1

Using the SAS data set Blood, generate one-way frequencies for the variables

Gender, BloodType, and AgeGroup. Use the appropriate options to omit the
cumulative statistics and percentages.

Solution:



Result:

Learning:
1# In this problem I have learnt how to generate frequency table 
2# I have used tables statement for compute frequency every variable in dataset
3# I have used nocum and noperecent that indicates that i do not want cumulative frequency as well as percentage.

Chapter#17 and Problem #3

Using the data set Blood, produce frequencies for the variable Chol (cholesterol).
Use a format to group the frequencies into three groups: low to 200 (normal), 201
and higher (high), and missing. Run PROC FREQ twice, once using the MISSING
option, and once without. Compare the percentages in both listings.

Solution:
Result:

Learning:
1# In this problem, I have proc format for formatting for labelling the output. it improves the appearance of the report when we used a format to label these values. 
2# proc freq used because I want to compute frequencies on formatted values, we can also use format to group values together into larger categories.

Chapter 18(Creating Tabular Reports)

In this chapter, I am  going to generate the report in tabular form. that displaying frequencies, percentages, and descriptive statistics (such as sums and means) broken by one or more CLASS variables.
Chapter#18 and Problem#1


All the problems, except Problem 10, use the SAS data set College.
Note: Data set College has permanent formats for Gender, SchoolSize, and Scholarship.
Either make this format catalog available to SAS (see Chapter 5), run the PROC
FORMAT statements here, or use the system option NOFMTERR (no format
error) that allows you to access SAS data sets that have permanent user-defined
formats without causing an error.
proc format;
value $yesno 'Y','1' = 'Yes'
'N','0' = 'No'
' ' = 'Not Given';
value $size 'S' = 'Small'
'M' = 'Medium'
'L' = 'Large'
' ' = 'Missing';
value $gender 'F' = 'Female'
'M' = 'Male'
' ' = 'Not Given';
run;
For each problem, you need to write the appropriate PROC TABULATE statements to
produce the given table.

Produce the following table. Note that the last row in the table represents all subjects.
Demographics from COLLEGE Data Set-

Solution:

Result:



Learning:
1# In this  problem, I have learnt what happened when we use proc tabulate data step 
2# proc tabulate uses a class statement to allow you to specify variables that represent category (often) character variable where we want to compute frequencies or percentage.
3# In this problem, gender, scholarship and schoolsize taken as a class variable and tables statement specify the appearance.
4# Any variable listed in a TABLE statement must be listed in a CLASS statement or a VAR statement (to be discussed shortly).

Chapter#18 and Problem #3

Produce the following table. Note that the ALL column has been renamed Total and
Gender has been formatted.
Demographics from COLLEGE Data Set

Solution:

Result:

Learning:
1# In this problem, I have broken down the school size in one or more variable of the class variable such as  gender or school size.
2# Here, I have combined frequencies and descriptive statistics in single table. 
3# School size broken into class gender, scholarship and school size.

Chapter 19 (Output Delivery System)

One of the most important changes in SAS, the introduction of Output Delivery System called as ODS. Each SAS procedure produce its unique output . This output was difficult to incorporate into other documents, such as Microsoft Office Word orMicrosoft Office PowerPoint.The Output Delivery System changed all that. Now each SAS procedure creates outputobjects that can be sent to such destinations as HTML, RTF, PDF, and SAS data sets.
 Not only can you send your SAS output to all of these formats, you can, if you are brave enough, customize the output’s fonts, colors, size, and
layout.

Chapter#19 and Problem#1

Run the following program, sending the output to an HTML file. Issue the
appropriate commands to prevent SAS from creating a listing file. See Chapter 16,
Problem 2, for the note about creating formats for this data set.
title "Sending Output to an HTML File";
proc print data=learn.college(obs=8) noobs;
run;
proc means data=learn.college n mean maxdec=2;
var GPA ClassRank;
run;

Solution:
Result:


Chapter#19 and Problem#3

Run the same two procedures as shown in Problem 1, except use the JOURNAL (or

FANCYPRINTER) style instead of the default style.

Solution:

Result:


Chapter 20(Generating High-Quality Graphics)

This chapter introduces some basic concepts behind SAS/GRAPH software. Here you
will see how to create simple bar charts, scatter plots, and line graphs. There are many
excellent books and manuals available from SAS Press.

Chapter#20 and Problem#3

Using the SAS data set Bicycles, produce a vertical bar chart showing the
distribution of Total Sales (TotalSales). Use midpoints of 0 to 12,000, with intervals
of 2,000.

Solution:

Result:


Chapter#20 and Problem#9

Using the SAS data set Stocks, produce a scatter plot of Price versus Date. Use the
dot as the plotting symbol and connect the dots with a smooth line.

Solution:

Result: