Turn on suggestions

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

Showing results for

Options

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 04-13-2019 12:02 AM
(704 views)

I have a code that contains parts from SAS/STAT and parts from Proc/IML.

The code censors data then calculate the area.

The censoring is done first for 500 observations then goes up to 5000 observations with increment of 500.

I need help in how to write the loop in this case. I am using SAS 9.4

Thanks a lot

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

That's fine. As I said, you can modify the program for other situations such as you describe.

```
N = 10154;
do case = 1 to 3;
if case=1 then
obsIdx = 501:N;
else if case=2 then
obsIdx = 1:(N-500);
else if case=3 then do;
middle = round(N/2);
midIdx = (middle-249):(middle+250); /* or -250 and +249 */
obsIdx = setdif(1:N, midIdx);
end;
...
end;
```

6 REPLIES 6

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I do not fully understand your problem, but do the various samples build on each other? Can you read in the final 5000 observations and then analyze the first 500, the first 1000, the first 1500, etc? (or maybe you are analyzing (1:500, 501:1000, ...? It's not clear.)

If so, here is the basic structure for subsetting the data. I assume you want to analyze 1:500, 1:1000, 1:1500, etc, but the program can be modified to other situations:

```
proc iml;
start TrapIntegral(x,y);
N = nrow(x);
dx = x[2:N] - x[1:N-1];
meanY = ( y[2:N] + y[1:N-1] )/2;
return( dx` * meanY );
finish;
grid = T( do(-5+0.002, 5, 0.002) );
density = pdf("Normal", grid); /* N(0,1) density on [-5, 5] */
N = nrow(density);
print N;
sizes = T( do(500, N, 500) );
Area = j(nrow(sizes), 1, .);
do i = 1 to nrow(sizes);
obsIdx = 1:sizes[i]; /* or sizes[i-1]:sizes[i] ? */
x = grid[obsIdx]; /* subset the data */
y = density[obsIdx];
Area[i] = TrapIntegral(x, y);
end;
print sizes Area;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thank you for your reply.

My issue is that I need to read and estimate the density for the data using three types of censoring

case 1: censoring from the begging, for this case I** will not** take the first 500 observations, I start my data from obs=501 till the end of the data.

case 2: censoring the last 500 observation, so my data will start from obs=1 and end with 10154-500

Case 3: censoring from the middle so I will read all the data except the 500 observations from the middle.

For each of these data sets I compute the kernel.

My problems is that I have to do it again for 1000, 1500,...,5000.

I have done it by adjusting the numbers manually and run the code, but this is very primitive and I want something rigorous.

Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

That's fine. As I said, you can modify the program for other situations such as you describe.

```
N = 10154;
do case = 1 to 3;
if case=1 then
obsIdx = 501:N;
else if case=2 then
obsIdx = 1:(N-500);
else if case=3 then do;
middle = round(N/2);
midIdx = (middle-249):(middle+250); /* or -250 and +249 */
obsIdx = setdif(1:N, midIdx);
end;
...
end;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You will need a macro %DO loop.

Something like this:

```
%macro dothis;
%do start = 1 %to 4501 %by 500;
proc whatever data=mydata(firstobs=&start obs=500);
...
run;
proc iml;
use mydata(firstobs=&start obs=500);
read var _num_ /* or a list of variable names */ into x;
...
quit;
%end;
%mend;
%dothis
```

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

use SUBMIT in IML.

proc iml;

.......

submit ;

proc reg data=class;

...........

endsub;

quit;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

That may work. Thanks!

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

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.