BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mariko5797
Pyrite | Level 9

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;
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10

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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 513 views
  • 0 likes
  • 3 in conversation