BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

I need to assign values to a variable (avisitnum) based on recent visit when the visit is unscheduled.

 

Eg. For the OBS 4, the avisitnum value is 2 because recent scheduled visit is scheduled2 and visitnum=2.

For unscheduled visit, the recent visitnum should be populated

 

data

 

id    period            date              visit                visitnum
1     period1    2015-06-02       scheduled1        1
1     period1     2015-06-07       scheduled2        2
1     period1     2015-06-23       scheduled3        3
1      period1     2015-06-17      unscheduled       99

 

output needed

id    period            date              visit                visitnum              avisitnum
1     period1    2015-06-02       scheduled1        1                         1
1     period1     2015-06-07       scheduled2        2                        2
1     period1     2015-06-23       scheduled3        3                         3
1      period1     2015-06-17      unscheduled       99                      2

3 REPLIES 3
Shmuel
Garnet | Level 18

Use:

 

proc sort data=have; by id period date; run;

data want;

 set have;

      prev_visitnum = lag(visitnum);

     if visit = "unscheduled" then visitnum - prev_visitnum;

     /* OR   if visitnum=99 then visitnum = prev_visitnum  */

     drop prev_visitnum;

 run;

mnjtrana
Pyrite | Level 9

 

Hey,

 

you can use the below code to populate the recent visit on the unscheduled visits.

 

data have;
length date 8 visit $12;
informat date yymmdd10.;
input id $ period $ date $ visit $ visitnum ;
datalines;
1     period1    2015-06-02       scheduled1        1
1     period1     2015-06-07       scheduled2        2
1     period1     2015-06-23       scheduled3        3
1     period1     2015-06-17      unscheduled       99
run;

proc sort data = have;
by id period date visitnum;
run;


data need(drop=a);
set have;
format date ddmmyyd10.;
retain avisitnum;
by id period date visitnum;
a = avisitnum;
if first.period then avisitnum=1;
else avisitnum+1;
if visitnum=99 then avisitnum=a;
run;

 

Untitled.jpg

hope this helps!

Manjeet


Cheers from India!

Manjeet
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Out of interest, what are you doing with avisitnum?  It looks a bit like your creating ADaM datasets here, you may want to check the CDISC documentation, as it is AVISIT, AVISITN, and there are examples on populating unscheduleds.  Its just if you keep that output, avisit looks duplicate.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 1002 views
  • 3 likes
  • 4 in conversation