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

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;
1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21
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

7 REPLIES 7
art297
Opal | Level 21
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

 

 

 

Cruise
Ammonite | Level 13
ha, worked out. I ignore "WARNING: Partial value initialization of the array rate."
Cruise
Ammonite | Level 13

@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;

 

art297
Opal | Level 21

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

 

Cruise
Ammonite | Level 13

@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?

art297
Opal | Level 21

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

 

Cruise
Ammonite | Level 13
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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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