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

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Assign first value for the array

Topic Options

- 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
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-22-2018 09:08 PM

How to assign first variable of the array to 0 here? Below code creates rate1-rate11 taking values from 0.1 through 1.1. But I want rate1 starts at 0 so that rate11 would take 1.

```
data check; set temp;
array rate rate01-rate11;
do i=1 to dim(rate);
rate(i)=i/10;
end;
drop i;
run;
```

Accepted Solutions

Solution

02-22-2018
09:17 PM

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

Posted in reply to Cruise

02-22-2018 09:15 PM

data check; set temp; array rate rate01-rate11 (0); do i=2 to dim(rate); rate(i)=(i-1)/10; end; drop i; run;

Art, CEO, AnalystFinder.com

All Replies

Solution

02-22-2018
09:17 PM

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

Posted in reply to Cruise

02-22-2018 09:15 PM

data check; set temp; array rate rate01-rate11 (0); do i=2 to dim(rate); rate(i)=(i-1)/10; end; drop i; run;

Art, CEO, AnalystFinder.com

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

Posted in reply to art297

02-22-2018 09:17 PM

ha, worked out. I ignore "WARNING: Partial value initialization of the array rate."

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

Posted in reply to art297

02-22-2018 09:29 PM

Bummer, I'm doing calculations using resulting array. The solution provided doesn't work with subsequent arithmetic functions. Any alternatives?

```
data check; set temp;
array rate rate01-rate21 (0);
do i=2 to dim(rate);
rate(i)=1+(i-1)/5;
end;
drop i;
run;
```

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

Posted in reply to Cruise

02-22-2018 09:35 PM

I don't understand what you're saying. Do the variables fate01 thru rate21 already exist in the file temp?

Show an example but, this time, include an example of what file temp looks like.

Art, CEO, AnalystFinder.com

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

Posted in reply to art297

02-22-2018 09:41 PM

This is temp:

this is what I'm trying to achieve:

```
data test_s1;
set temp(where=(county=1));
denom=tot_pop+sum_inflow-sum_outflow;
array rate rate01-rate21 (0);
do i=2 to dim(rate);
rate(i)=((tot_case+(agerisk*((i-1)/5)*sum_inflow)-agerisk*sum_outflow)/denom)*us_age_dist;
end;
drop i;
run;
```

the problem is that rate01 turns out to be 0 in test_s1. however, rate01 is not supposed to be zero, right?

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

Posted in reply to Cruise

02-22-2018 10:32 PM

You said, in your first post, that you want rate01 to have a value of 0. What am I missing?

Do you really only want rate01 to rate20 with each variable taking on the stated computation?

Art, CEO, AnalystFinder.com

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

Posted in reply to art297

02-22-2018 10:44 PM

I replaced 'do i=2' to 'do i=1' which solved the problem. Because I wanted rate01 take zero and get it's value reflected in the subsequent computation.