"How do I apply a format to a vector of values in IML? In the DATA step, I can just call the PUTN function.”
This question came from a SAS customer that I met recently at a conference. My reply? Use the PUTN function, but send it a vector of values.
In particular, there is no need to write a loop. Just put in a vector of numbers and you’ll get out a character vector that contains the formatted values:
proc iml; v = {0.01 0.05 0.1 0.5 0.9 0.95 0.99}; p = putn(v, "Percent6.3"); print p; |
You can send a SAS/IML matrix to almost every DATA step function. For example, to compute the quantiles of the standard normal distribution that correspond to the values of v, just call the QUANTILE function in Base SAS:
q = quantile("Normal", v); print q[format=6.3]; |
Neither the PUTN function nor the QUANTILE function are explicitly listed in the Language Reference section of the SAS/IML User’s Guide, because they are not technically part of the SAS/IML language. However, they are mentioned in the section titled "Base SAS Functions Accessible from SAS/IML Software."
10 Comments
If I want use Lag function in Base/SAS, how do I do?
LAG is a function that IML does not support in SAS 9.2 (but will in the next release). You can write a simple module to compute the lag of a column vector:
proc iml;
start lag(x, d);
n = nrow(x);
y = j(n, 1, .);
if n >= d then
y[d+1:n] = x[1:n-d];
return( y );
finish;
x = {1,2,3,4,5};
x1 = lag(x, 1);
x2 = lag(x, 2);
print x1 x2;
The LAG function is here!
http://support.sas.com/documentation/cdl/en/imlug/64248/HTML/default/viewer.htm#imlug_langref_sect172.htm
Pingback: A Simple Signum Function - The DO Loop
Pingback: Need case-insensitive string comparisons? UPCASE! - The DO Loop
Pingback: Calling Base SAS functions from SAS/IML: How to handle argument lists? - The DO Loop
Pingback: Detecting missing values in the SAS/IML language - The DO Loop
Pingback: Removing Observations with Missing Values - The DO Loop
Pingback: Call Base SAS functions with vectors of arguments - The DO Loop
Pingback: Pascal’s triangle in SAS - The DO Loop