In Problems 1-6, you are writing sas macros for other users. The macros should be written so that if a user calls the macro, all he/she needs to do is to use the right dataset and call your macro with the correct arguments. He/she will get either the output printed or new data set.
1. Refer to the CLINTON dataset. Suppose the future record will always be in this format. Write a macro to output a 95% confidence interval for the true proportion when the sample proportion is given from a sample of size n. The inputs are dataset name, date, which proportion (approval or disapproval rate) and sample size. The outputs should be the date selected and the 95% confidence interval for the proportion. Test your macro by the CLINTON dataset. Call the macro twice with one for the Oct 27, 1997 approval rate and the other for the May 9, 1996 disapproval rate. Assume that the sample size were 1,500.
2. Refer to the DOGS1 dataset. Suppose the future record will always be in this format. Write a macro to output the monthly weight gain (=weight/age) of each dog. Let M be the maximum age for growth, i.e., age M will be used in this formula if a dog is older than this age. The inputs are dataset name, gender and the age upper limit M. The outputs should be the dogs with the selected gender, their weights, ages and weight gains. Test your macro by the DOGS1 dataset. Call the macro for male dogs with age limit M=24 months.
3. Refer to the USEDCARS dataset. Suppose the future record will always be in this format. Write a macro that will summarize the used cars for a selected manufacturer. We need the number of cars (sample size), the mean price, the median price and the standard deviation of the sample in the output data set. The arguments of the macro are: input date set name, manufacturer and output data set name. Test your macro by the USEDCARS dataset for Ford cars. Print the information in the output dataset.
4. Refer to the CATS1, CATS2, CATS3 datasets. Suppose the future record will always be in these formats. Write a SAS macro to reorganize the data so that the output file will be in the following arrangement:
OBS NAME TREATED LEFT0 LEFT1 LEFT2 RIGHT0 RIGHT1 RIGHT2 1 Attila Left 1.11 0.89 1.03 1.21 1.13 1.16 2 Bill Right 1.06 1.07 1.03 1.04 0.89 1.01 3 Catbert Left 1.25 1.03 1.11 1.27 1.22 1.21 4 Felix Right 1.28 1.35 1.33 1.42 1.21 1.34 5 Garfield Left 1.34 1.05 1.19 1.37 1.36 1.29 6 Hobbes Left 0.89 0.75 0.94 0.99 0.93 1.01 7 Scratchy Right 1.07 1.08 1.14 1.04 0.89 1.02 8 Stimpy Right 1.21 1.25 1.17 1.11 0.99 1.04The macro's arguments should be three input file names and one output file name. Use the CATS data to test your macro.
5. Write a macro that can take a random sample size of n from an input data set. The arguments for the micro should be the dataset name, sample size, seed for random numbers, and the output file name. Test your macro by using the USEDCARS dataset. Use two different seeds to take two random samples of size 10 and print your sample in the original data format. (Hint: Attach each datum with a random number, delete the datum if its rank is larger than the sample size.)
6. Write a macro that can generate a normal or uniform data set with any required size. The arguments of the macro should contain the required mean, standard deviation (sd), distribution, required size, seed, and output file name. Test your macro by calling it twice one for 300 normal deviates with mean=10 sd=4, and one for 300 uniform deviates with with mean=10 and sd=4. Use PROC CHART to plot the histograms of the output files.
7. The macro check given in Example 2 of the lecture is saved in http://www.stat.ufl.edu/~yang/STA5106/lesson13 as check.sas Call this macro and apply to the dataset MANATEES using the regression option with y=all watercraft and x=year. Print the output from the macro. (Due to security reasons, you may not be able to fetch this file from our web. In this case, please copy it from the notes.)
8. The macro density given in Example 1 of the lecture is saved in http://www.stat.ufl.edu/~yang/STA5106/lesson13 as density.sas. Call this macro and apply to the dataset cities. Print the output file from the macro. (Due to security reasons, you may not be able to fetch this file from our web. In this case, please copy it from the notes.)