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

Hello All,

I'm trying to find the number of days between the occurrence of rainfall events. Here's a sample of my code:

Date          precip_cm

1/1/61          0.13

1/2/61          0

1/3/61          0

1/4/61          0

1/5/61          0.64

1/6/61          0.32

1/7/61          0

1/8/61          0

1/9/61          0

1/10/61        0 

I'd like to add a new column that shows the number of days since the last rainfall occurred. Here's an example of what I'm trying to do:

Date          precip_cm          days_since_rf

1/1/61          0.13                     0

1/2/61          0                         1

1/3/61          0                         2

1/4/61          0                         3

1/5/61          0.64                    0   

1/6/61          0.32                    0

1/7/61          0                         1

1/8/61          0                         2    

1/9/61          0                         3

1/10/61        0                         4

Does anyone have any suggestions on how to do this? Thanks in advance for your help!

Salli

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

data want;

set have;

retain days_since_rf;

if precip_cm ne 0 then days_since_rf=0;

else days_since_rf+1;

run;

View solution in original post

2 REPLIES 2
Reeza
Super User

data want;

set have;

retain days_since_rf;

if precip_cm ne 0 then days_since_rf=0;

else days_since_rf+1;

run;

sfd
Calcite | Level 5 sfd
Calcite | Level 5

Thank you @Reeza! Your code did the trick.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 400 views
  • 0 likes
  • 2 in conversation