BookmarkSubscribeRSS Feed
Vic6
Fluorite | Level 6

Hi guys,

 

Please help me out with the following topic. I want to find a way to automatically calculate values for variable y2. Variables x and y1 are already calculated.

The rules for calculation of y2 variable are the followings:

1) If y1=-1 (day 3), the value of y1 from the day1 and day2=0 and in the next day (day 4) y1=0 then the counter for y2 (day 3) is -1.

2) If there is no counter reset (i.e. y1 from day 16=-2 and y1 from day 18=-1) then y2 from day 18=-4. In day 19, y2 should be -8 as there still is no counter reset. Same with day 21, when y2 should be -16.

 

The counter resets only in the following conditions:

- if y1 from previous day and y1 from next day =0 (e.g. day2=0, day3=-1 and day4=0 -> day 5 counter reset);

- if y1 from next two days=0 (e.g day5=-1, day6=-2, day7=0, day8=0 ->in day9 counter reset).

 

Day_noxy1y2
1100
2100
32-1-1
4100
54-1-1
63-2-2
7100
8100
9100
10100
112-1-1
12100
13500
14600
157-1-1
162-2-2
17100
186-1-4
192-2-8
20100
213-1-16
22100
23100
245-1-1
25100
4 REPLIES 4
Vic6
Fluorite | Level 6
It seems to be a mistake in my conditions...The correct value for y2 in day 21 should be -16 because there is no counter reset between day 19 and day 21. The break will take place in day 23 since day 20=0, day 21=-1 and day 22=0.
The condition #1 would apply only in case we would had a day 0 with y1=0.
Kurt_Bremser
Super User

Then you need to rephrase your conditions until they lead to exactly the outcome that you want, and do not contradict it in places.

See Maxim 42, a well-done question will be 90% of the answer.

Vic6
Fluorite | Level 6

Conditions have been updated in the initial message.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1149 views
  • 0 likes
  • 2 in conversation