Publications by Ken Kleinman
Example 7.10: Get data from R into SAS
In our previous entry, we described how to generate a dataset from SAS that could be used for analyses in R. Alternatively, someone primarily using R might want to test the new ”statistical graphics” procedures available starting with SAS 9.2. Here we show how one might create a long data set in R, export it, read it in SAS, and ...
1449 sym R (996 sym/3 pcs) 6 img
Example 7.11: Plot an empirical cumulative distribution function from scratch
In example 7.8, we used built-in functions to produce an empirical CDF plot. But the empirical cumulative distribution function (CDF) is simple to calculate directly, and it might be useful to have more control over its appearance than is afforded by the direct method employed in example 7.8. In a later post, we’ll use that contr...
1554 sym R (486 sym/2 pcs) 6 img
Example 7.14: A simple graphic of sales
In this example, we show a simple plot of the sales rank data read in as shown in example 7.13.SASIn SAS, we use the symbol statement (section 5.3) to request small (with the h option) dots (with the v option, and that the dots not be connected (with the i option. (See sections 5.2.2, 5.3.9 for more details.)we request a scatter plot...
802 sym 2 img
Example 7.15: A more complex sales graphic
The plot of Amazon sales rank over time generated in example 7.14 leaves questions. From a software perspective, we’d like to make the plot prettier, while we can embellish the plot to inform our interpretation about how the rank is calculated.For the latter purpose, we’ll create an indicator of whether the rank was recorded in n...
803 sym 2 img
Example 7.18: Displaying missing value categories in a table
When displaying contingency tables (section 2.3.1), there are times when it is useful to either show or hide the missing data category. Both SAS and the typical R command default to displaying the table only for observations where both factors are observed.In this example, we generate some multinomial data (section 1.10.4) and then p...
784 sym 2 img
SAS and R included on R bloggers
The R bloggers site is an aggregator for blogs about R. We’re excited to be joining that community and suggest any readers of this blog may also find it useful. Related To leave a comment for the author, please follow the link and comment on their blog: SAS and R. R-bloggers.com offers daily e-mail updates about R news and tuto...
565 sym 2 img
Example 7.19: find the closest pair of observations
Suppose we need to find the closest pair of observations on some variable x. For example, we might be concerned that some data had been accidentally duplicated. We return the ID’s of the two closest observations, and their distance from each other. In both languages, we’ll first create the data, then sort it, recognizing that t...
803 sym 2 img
Example 7.20: Simulate categorical data
Both SAS and R provide means of simulating categorical data (see section 1.10.4). Alternatively, it is trivial to write code to do this directly. In this entry, we show how to do it once. In a future entry, we’ll demonstrate writing a SAS Macro (section A.8.1) and a function in R (section B.5.2) to do it repeatedly.SASdata test;p...
800 sym 2 img
Example 7.21: Write a function to simulate categorical data
In example 7.20, we showed how to simulate categorical data. But we might anticipate needing to do that frequently. If a SAS function weren’t built in and an equivalent R function not available in a package, we could build them from scratch.SASThe SAS code is particularly tortured, since we must parse the parameter string to extra...
803 sym 2 img
Example 7.23: the Monty Hall problem
The Monty Hall problem illustrates a simple setting where intuition often leads to a solution different from formal reasoning. The situation is based on the game show Let’s Make a Deal. First, Monty puts a prize behind one of three doors. Then the player chooses a door. Next, (without moving the pize) Monty opens an unselected d...
802 sym 2 img