turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-26-2012 11:01 AM

It is an easy job if the gap between the first number and the last is a multiple of the step size; however, I want to do it in more general cases.

For example, if I want to generate a seris starting from 1 until 45 while the value increases by 4 each time.

In matlab, we can type 1:4:45 and it gives [1 5 9 ... 41 45]; If I write 2:4:45, it will give [2 6 10 ... 42].

I know I can write a loop in SAS, but it could be increase the computation time dramatically. Is there an easier way to do it?

Thanks.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to bigbigben

01-26-2012 11:15 AM

The matlab syntax is NSTART: INCR: NSTOP. You can do the same in SAS/IML by using the DO function:

x = do( nstart, nstop, incr);

For example,

x = do( 1, 45, 4);

y = do( 2, 45, 4);

For more on this topic (including the SAS/IML equivalent of the linspace() function in MATLAB), see http://blogs.sas.com/content/iml/2011/01/10/creating-vectors-that-contain-evenly-spaced-values/

If you need to generate points on a 2D grid, see http://blogs.sas.com/content/iml/2011/01/21/how-to-create-a-grid-of-values/

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to bigbigben

01-26-2012 11:15 AM

PROC IML;

i = DO(2,45,4);

PRINT i;

QUIT;

All of the questions you are asking on the SAS/IML forum are rather basic. May I suggest that you buy (or borrow) Rick's book to properly learn IML from scratch?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to TomTom

01-26-2012 11:30 AM

Questions at all levels are welcome. It is often difficult for a beginner to get started, especially when you are coming from another language like MATLAB.

TomTom correct mentions that there are some resources that might help you with the learning curve:

- the SAS/IML Tip sheet

- a short (and not complete) "MATLAB to SAS/IML Tip Sheet"

- the FREE chapter of my book [HIGHLY RECOMMENDED]

- Read the article "How to learn SAS/IML: Five resources for the beginner"

In the "How to learn SAS/IML" article, the 3rd suggestion is "ask questions at the SAS/IML discussion forum"! So (IMHO), feel free to ask for help when you get stuck.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to bigbigben

01-26-2012 11:38 AM

Rick and TomTom. Many thanks for your response and help. I used Matlab pretty often before, and there are tons of sample codes of user-defined functions online that I can borrow or use as references. It is not very easy to find such resources in SAS. As my defense, even I read Rick's book, I probably don't remember all the functions used in SAS/IML. That being said, I will read all the documents recommended by both of you.

Best wishes.