Key

• This line was removed.
• Formatting was changed.
Excerpt

This example illustrates how you can apply functions to generate random numeric data in your dataset.

Functions:

D generate list excerpts
pages RANDBETWEEN Function,PI Function,ROUND Function,TRUNC Function,POW Function

Source:

In the following example, a company produces 10 circular parts, the size of which is measured in each product's radius in inches.

p0011
p0022
p0033
p0044
p0055
p0066
p0077
p0088
p0099
p01010

Based on the above data, the company wants to generate some additional sizing information for these circular parts, including the generation of two points along each part's circumference where quality stress tests can be applied.

Transformation:

To begin, you can use the following steps to generate the area and circumference for each product, rounded to three decimal points:

D trans
RawWrangle true 'area_sqin' step derive type:single value: ROUND(PI() * (POW(radius_in, 2)), 3) as: 'area_sqin' Formula type Single row formula Formula ROUND(PI() * (POW(radius_in, 2)), 3) New column name New formula

D trans
RawWrangle true 'circumference_in' step derive type:single value: ROUND(PI() * (2 * radius_in), 3) as: 'circumference_in' Formula type Single row formula Formula ROUND(PI() * (2 * radius_in), 3) New column name New formula

For quality purposes, the company needs two tests points along the circumference, which are generated by calculating two separate random locations along the circumference. Since the `RANDBETWEEN` function only calculates using Integer values, you must first truncate the values from `circumference_in`:

D trans
RawWrangle true 'trunc_circumference_in' step derive type:single value: TRUNC(circumference_in) as: 'trunc_circumference_in' Formula type Single row formula Formula TRUNC(circumference_in) New column name New formula

Then, you can calculate the random points using the following:

D trans
RawWrangle true 'testPt01_in' step derive type:single value: RANDBETWEEN(0, trunc_circumference_in) as: 'testPt01_in' Formula type Single row formula Formula RANDBETWEEN(0, trunc_circumference_in) New column name New formula

D trans
RawWrangle true 'testPt02_in' step derive type:single value: RANDBETWEEN(0, trunc_circumference_in) as: 'testPt02_in' Formula type Single row formula Formula RANDBETWEEN(0, trunc_circumference_in) New column name New formula

Results:

After the `trunc_circumference_in` column is dropped, the data should look similar to the following: