BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
knveraraju91
Barite | Level 11

data want; do week=1 to 100; day=week+1; llc=day+; ulc=day+; end; run;

Dear,

I need help in DO iterative code. I need to skip every third number and create two variables for each row by adding different numbers.

eg; for  1,2,3  combination I need to skip 3 and  create llc and ulc variables for 1,2.

For row 1, i need to calculate  llc=day+2 and ulc=day+5.

For row 2, i need to calculate llc=day+3 and ulc=day+6

I need to repeat above for all three set combinations.  Please suggest. Thank you

output needed

week  day  llc  ulc

1        2          4     7

2       3          6      9

4        5         7      10

5        6         9       12

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Here one option

data want;
  do week=1 to 100;
    rem=mod(week,3);
    if rem = 0 then continue;
    day=week+1;
    llc=day+1+rem;
    ulc=day+4+rem;
    output;
  end;
  drop rem;
run;

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Did you mean something like this?

data want;
 week=0;
 day=1;
 do until(week>10);
   do inc=1 to 3;
     week+1;
     day+1;
     llc=day+1+inc;
     ulc=day+4+inc;
     if inc<3 then output;
     else week+-1;
   end;
 end;
 drop inc;
run;
Obs    week    day    llc    ulc

  1      1       2      4      7
  2      2       3      6      9
  3      3       5      7     10
  4      4       6      9     12
  5      5       8     10     13
  6      6       9     12     15
  7      7      11     13     16
  8      8      12     15     18
  9      9      14     16     19
 10     10      15     18     21
 11     11      17     19     22
 12     12      18     21     24
Patrick
Opal | Level 21

Here one option

data want;
  do week=1 to 100;
    rem=mod(week,3);
    if rem = 0 then continue;
    day=week+1;
    llc=day+1+rem;
    ulc=day+4+rem;
    output;
  end;
  drop rem;
run;

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 367 views
  • 2 likes
  • 3 in conversation