Hi everyone,
I am stuck on a data management task and thought someone here may be able to help me.
I am working with a dataset where each individual has ~30 rows of repeated data. The variables with information that differs are dates and a variable that indicates the first for each group. I'd like to add 7 number of days to every row, by group. I have a start date for the first row for each individual and need to add 7 days to each row until the next individual is reached (e.g., row 31) where the same process is repeated. Any suggestions? Here is what I have and what i want the data to look like. Thank you!!
data have; input id date first; datalines; 1 03OCT2010 1 1 . 0 1 . 0 1 . 0 2 01JAN2011 1 2 . 0 2 . 0 ; run; data want; input id date first; datalines; 1 03OCT2010 1 1 10OCT2010 0 1 17OCT2010 0 1 24OCT2010 0 2 01JAN2011 1 2 08JAN2011 0 2 15JAN2011 0 ; run;
As long as FLAG=1 for the first record of each id, this will work:
data want;
set have;
retain tmpdate 0;
tmpdate=ifn(flag=1,date,tmpdate+7);
if flag^=1 then date=tmpdate;
drop tmpdate;
run;
As long as FLAG=1 for the first record of each id, this will work:
data want;
set have;
retain tmpdate 0;
tmpdate=ifn(flag=1,date,tmpdate+7);
if flag^=1 then date=tmpdate;
drop tmpdate;
run;
This works beautifully! Thank you.
I'm trying to understand how this works.
What does the carrot in following line do?
flag^=1
@pamplemouse22 wrote:
This works beautifully! Thank you.
I'm trying to understand how this works.
What does the carrot in following line do?
flag^=1
^= is "not equal" . There are some other ways depending on different keyboards/operating systems that are also acceptable.
so
Flag not equal to 1
oh, hah! that makes sense. thank you!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: