BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MDaniel
Obsidian | Level 7

Is there a way to write the 5th line below so that it works (while keeping it within a single expression / single line) ?

More generally, how can a vector be initiated by specifying formulas instead of values for each element?

 

proc iml;
	x = j(3,2,.);
	do i = 1 to nrow(x);
		/*this doesn't work*/
		x[i,] = { i 0 };

		/*this does work, but it's an extra line */
		x[i,1] = i;
		x[i,2] = 0;
	end;
quit
1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

The direct answer to your question is to use the horizontal concatenation operator (||)

x[i,] = i || 0;

as described in the article "How to build a vector from expressions."

 

Of course, for this example, you don't need a loop at all:

proc iml;
x1 = T( 1:3 );
x2 = j(nrow(x1), 1, 0);
x = x1 || x2;

View solution in original post

1 REPLY 1
Rick_SAS
SAS Super FREQ

The direct answer to your question is to use the horizontal concatenation operator (||)

x[i,] = i || 0;

as described in the article "How to build a vector from expressions."

 

Of course, for this example, you don't need a loop at all:

proc iml;
x1 = T( 1:3 );
x2 = j(nrow(x1), 1, 0);
x = x1 || x2;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 1 reply
  • 845 views
  • 0 likes
  • 2 in conversation