I want unscheduled visits indicated by *.19 and *.2 to be marked as such in AVISITN and AVIST. For example, I want ID = 1, VISITNUM = 104 to result in AVISITN = 202.19, AVISIT = "3 Days Post Dose 2 (S)". However, both AVISITN and AVISIT are coming up as blank for those visits.
data have;
input ID VISIT $ VISITNUM @@;
cards;
1 DAY1 101
1 DAY2 102
1 DAY3 103
1 DAY4 104.19
1 DAY5 105
2 DAY1 101
2 DAY2 102.2
2 DAY3 103
3 DAY1 101
3 DAY2 102
3 DAY3 103.19
3 DAY4 104
3 DAY5 105
;
run;
data have2;
set have;
length avisit1 $30.;
visitnum1 = int(visitnum);
if visitnum1 = 101 then do; avisit1n = 101; avisit1 = 'Dose 1'; end;
if visitnum1 = 102 then do; avisit1n = 102; avisit1 = '3 Days Post Dose 1';end;
if visitnum1 = 103 then do; avisit1n = 201; avisit1 = 'Dose 2'; end;
if visitnum1 = 104 then do; avisit1n = 202; avisit1 = '3 Days Post Dose 2';end;
if visitnum1 = 105 then do; avisit1n = 203; avisit1 = '7 Days Post Dose 2';end;
if visitnum ^= visitnum1 then do;
if visitnum-visitnum1 = 0.19 then do; avisitn = avisit1n + 0.19; avisit = strip(avisit1)||' (S)'; end;
if visitnum-visitnum1 = 0.20 then do; avisitn = avisit1n + 0.20; avisit = strip(avisit1)||' (T)'; end;
end;
else do; avisitn = avisit1n; avisit = avisit1; end;
run;
Aside: I attempted to make WANT dataset, but it kept reading each spacing as a new variable.
data want;
input ID AVISIT $ AVISITN @@;
length AVIST $18.;
cards;
1
Dose 1
101
1
3 Days Post Dose 1
102
1
Dose 2
201
1
3 Days Post Dose 2 (S)
201.19
1
7 Days Post Dose 2
203
2
Dose 1
101
2
3 Days Post Dose 1 (T)
102.2
2
Dose 2
201
3 Dose 1 101
3
3 Days Post Dose 1
102
3
Dose 2 (S)
201.19
3
3 Days Post Dose 2
202
3
7 Days Post Dose 2
203
;
run;
Computers cannot represent fractions (that are not integer powers of 2) exactly. So, if you want to find something that equals a fractional value, you may have to round.
Try
if round(visitnum-visitnum1,0.01) = round(0.19,0.01) then do;
or use the FUZZ function
if fuzz(visitnum-visitnum1-0.19)=0 then do;
Computers cannot represent fractions (that are not integer powers of 2) exactly. So, if you want to find something that equals a fractional value, you may have to round.
Try
if round(visitnum-visitnum1,0.01) = round(0.19,0.01) then do;
or use the FUZZ function
if fuzz(visitnum-visitnum1-0.19)=0 then do;
You could try the resolve() function to evaluate that expression in the section of the DATA step that seems to be causing the issue. Like this:
if resolve(visitnum-visitnum1) = 0.19 then do; avisitn = avisit1n + 0.19; avisit = strip(avisit1)||' (S)'; end;
if resolve(visitnum-visitnum1) = 0.20 then do; avisitn = avisit1n + 0.20; avisit = strip(avisit1)||' (T)'; end;
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 25. 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.