DATA Step, Macro, Functions and more

Assign first value for the array

Accepted Solution Solved
Reply
Super Contributor
Posts: 383
Accepted Solution

Assign first value for the array

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
Super User
Posts: 8,217

Re: Assign first value for the array

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

 

 

 

View solution in original post


All Replies
Solution
‎02-22-2018 09:17 PM
Super User
Posts: 8,217

Re: Assign first value for the array

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

 

 

 

Super Contributor
Posts: 383

Re: Assign first value for the array

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

Re: Assign first value for the array

@art297

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;

 

Super User
Posts: 8,217

Re: Assign first value for the array

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

 

Super Contributor
Posts: 383

Re: Assign first value for the array

@art297

This is temp:

temp.png

 

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?

Super User
Posts: 8,217

Re: Assign first value for the array

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

 

Super Contributor
Posts: 383

Re: Assign first value for the array

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.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 131 views
  • 2 likes
  • 2 in conversation