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

Hi All,

 

I want to find out the future date from the current date with 'x' number of days. the data is as follows.

 

4.jpg

 

Now I want to add the number of days mentioned in the 'Count' column in the 'Visit Date' column and it should be stored in Next Visit date Column if the visit date for the current visit is not mentioned.

 

E.g. - The Patient 101 is having visit date till visit no 4 (21-Jan-16) then to find out his next visit date (for visit no 5), I want the '28' (from count variable) to be added in his visit number 4 date i.e. 21-jan-16 and stored it in 'Next Visit Date' column (21-jan-16 + 28 = 18-Feb-16). if his next visit date (i.e. visit 6) is also missing then the next corresponding count value to be added in 'Next Visit Date' column (18-Feb-16 + 28 = 17-Mar-16) and it is stored in 'Next Visit Date' column and so on. 

 

Now the patient 102 only has one visit date then I want to find out His Next Visit Dates based on the count mentioned in the corresponding observation till visit no 6.

 

The final result should look like as below.

 

5.jpg

 

Thank you very much for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Yeah. Nobody like picture. Nobody would like to type it for you . Post it in text and better is SAS code .

Next time ,don't forget it.

 

 

data have;
input patient visitno visitdate : date9. count;
format visitdate  date9. ;
cards;
101 1 1jan16 1
101 2 2jan16 6
101 3 8jan16 7
101 4 21jan16 13
101 5 . 28
101 6 . 28
101 7 . 28
102 1 1feb16 1
102 2 . 6
;
run;

data want;
 set have;
 by patient ;
 retain temp;
 if first.patient then call missing(temp);
 if not missing(visitdate) then newvisitdate=visitdate;
  else newvisitdate=temp+count;
 temp=newvisitdate;
 drop temp;
 format newvisitdate date9.;
run;

View solution in original post

10 REPLIES 10
LinusH
Tourmaline | Level 20

Have the visit date from the previous observation stored in a retained variable, and use that as part of the calculation for the next visit date.

Data never sleeps
PGStats
Opal | Level 21

Just a note. Posting your data as a picture will not get you a tested solution. My SAS doesn't read pictures.

PG
Ksharp
Super User

Yeah. Nobody like picture. Nobody would like to type it for you . Post it in text and better is SAS code .

Next time ,don't forget it.

 

 

data have;
input patient visitno visitdate : date9. count;
format visitdate  date9. ;
cards;
101 1 1jan16 1
101 2 2jan16 6
101 3 8jan16 7
101 4 21jan16 13
101 5 . 28
101 6 . 28
101 7 . 28
102 1 1feb16 1
102 2 . 6
;
run;

data want;
 set have;
 by patient ;
 retain temp;
 if first.patient then call missing(temp);
 if not missing(visitdate) then newvisitdate=visitdate;
  else newvisitdate=temp+count;
 temp=newvisitdate;
 drop temp;
 format newvisitdate date9.;
run;
VikrantSawatkar
Obsidian | Level 7
Please accept my apologies. I will not post images hereafter.

Thank you very much for your help.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
FreelanceReinh
Jade | Level 19

Hi @VikrantSawatkar,

 

Once you have verified that Ksharp's suggestion solves your problem, it would be good if you marked his reply as the accepted solution (by clicking the respective button "Accept as Solution"). Please see this article why this is important.

VikrantSawatkar
Obsidian | Level 7

Thank you for the help. It is working perfectly.

FreelanceReinh
Jade | Level 19

Hi @VikrantSawatkar,

 

There are "Accept as Solution" buttons in every post and, of course, you should click the one pertaining to the solution. That's why I underlined the word "respective" in 'by clicking the respective button "Accept as Solution"'. Unfortunately, you still managed to click the wrong button. Not sure if you can change it. But you could at least give likes to the actual solution (by pressing the respective orange "applause" button).

 

Edit: Maybe Super Users or community administrators (@ChrisHemedinger?) can correct this.

PGStats
Opal | Level 21

The super users don't seem to have that power. I think the op can un-accept a solution by clicking the "Not the solution" choice on the wrong answer's menu. (untested)

PG
VikrantSawatkar
Obsidian | Level 7

I am sorry. I'm a new user here. And I was not aware of it.  Next time onwards,  I will keep it in my mind. 

 

Also,  the solution provided by Ksharp is correct. I'm able to get the desired results with it. 

 

Thank you very much for your help. 

ChrisHemedinger
Community Manager
Done - @Ksharp now has the correct solution.
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

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
  • 10 replies
  • 1362 views
  • 6 likes
  • 6 in conversation