Repetition factors versus frequency variables

0

A regular reader noticed my post on initializing vectors by using repetition factors and asked whether that technique would be useful to expand data that are given in value-frequency pairs. The short answer is "no." Repetition factors are useful for defining (static) matrix literals. However, if you want to expand data dynamically, I recommend that you use the REPEAT function or the technique in the article on expanding data by using frequencies.

For example, the following SAS/IML statement defines a vector for which the value 2.2 is repeated two times and the value 3.3 is repeated three times. The resulting vector has five elements:

proc iml;
x = {[2] 2.2  [3] 3.3};

This vector is constructed as a matrix literal. If instead you have the values and frequencies in separate vectors, then use the ExpandFreq module in my previous post:

values = {2.2 3.3};
freq   = {2   3};
load module=(ExpandFreq); /* define or load ExpandFreg module here */
y = ExpandFreq(values, freq);

This is probably a good time to remind everyone about the SAS/IML Support Community. You can post your SAS/IML questions there 24 hours a day. That is always better than sending me direct email. There are lots of experienced SAS/IML experts out there, so use the SAS/IML Support Community to tap into that knowledge.

Share

About Author

Rick Wicklin

Distinguished Researcher in Computational Statistics

Rick Wicklin, PhD, is a distinguished researcher in computational statistics at SAS and is a principal developer of SAS/IML software. His areas of expertise include computational statistics, simulation, statistical graphics, and modern methods in statistical data analysis. Rick is author of the books Statistical Programming with SAS/IML Software and Simulating Data with SAS.

Leave A Reply

Back to Top