DATA Step, Macro, Functions and more

Assign an incremental sub count to numeric variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

Assign an incremental sub count to numeric variable

[ Edited ]

if Visitn=999, then need to change it to scheduled.
EX: If the previous Visit is 7, and if the next visit is Unschedule then AVISITN=7.1,
if the same vist has more than one unschedule, then seq schould come as 7.1,7.2..

 

 haow can i change

 

 

eg; 1

       2

       3

      4

      5

      999

      6

after 5 i want 5.1, 5.2 how can i get plz help....


Accepted Solutions
Solution
‎09-12-2017 08:25 AM
Respected Advisor
Posts: 4,665

Re: SAS

@Aswanth

If you want answers providing code then you need to provide representative sample data (as a fully working SAS data step creating such sample data) and then clearly show the desired result.

View solution in original post


All Replies
Super User
Posts: 6,626

Re: SAS

[ Edited ]

I'm going to assume you have more variables in your data set ... at least a patient identifier so you know which visit belongs to which patient.

 

What should happen if the first visit is 999 for a patient?  Well, I will assume you want AVISITN to be 0.1, 0.2, etc.

 

proc sort data=have;

by patient visitn;

run;

 

data want;

set have;

by patient;

if first.patient then avisitn=0;

if visit=999 then avisitn + 0.1;

else avisitn = visitn;

run;

 

********** EDITED:

 

Upon further reflection, the sort should be by PATIENT only:

 

proc sort data=have;

by patient;

run;

 

Otherwise, it put's all the patient's 999 visits at the end, which is the wrong order.  If you have a variable that would put the in the proper order, you can use that as well:

 

proc sort data=have;

by patient date;

run;

Occasional Contributor
Posts: 18

Re: SAS

Posted in reply to Astounding
thank you so much
Occasional Contributor
Posts: 18

Re: SAS

but its not worked for me
Super Contributor
Posts: 285

Re: SAS

Please see the first example code in this article (https://www.mwsug.org/proceedings/2009/stats/MWSUG-2009-D14.pdf).

Solution
‎09-12-2017 08:25 AM
Respected Advisor
Posts: 4,665

Re: SAS

@Aswanth

If you want answers providing code then you need to provide representative sample data (as a fully working SAS data step creating such sample data) and then clearly show the desired result.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 167 views
  • 0 likes
  • 4 in conversation