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

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; 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

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;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

4 REPLIES 4
mkeintz
PROC Star

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;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
pamplemouse22
Calcite | Level 5

This works beautifully! Thank you. 

 

I'm trying to understand how this works. 

What does the carrot in following line do?

flag^=1

 

ballardw
Super User

@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

pamplemouse22
Calcite | Level 5

oh, hah! that makes sense. thank you!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 1677 views
  • 0 likes
  • 3 in conversation