Hello,
I'm using this bit of code to map AVISIT/AVISITN for an ADaM dataset. My question is there a way to use functions like INDEX,SUBSTR or LIKE to map UNSCHEDULED visits as currently AVISITN is blank for this condition but this is because AVISIT is "UNSCHEDULED 1.01". I know there is other ways of doing this but just curious if it can be done this way.
* AVISITN, AVISIT;
select (upcase(visit));
when ("SCREENING") avisitn = 10;
when ("DAY 1") avisitn = 20;
when ("WEEK 2") avisitn = 30;
when ("WEEK 4") avisitn = 40;
when ("WEEK 8") avisitn = 50;
when ("WEEK 12") avisitn = 60;
when ("WEEK 16") avisitn = 70;
when ("WEEK 20") avisitn = 80;
when ("RESCUE THERAPY") avisitn = 90;
when ("EARLY TERMINATION") avisitn = 100;
when ("UNSCHEDULED") avisitn =99;
otherwise put "Check: " avisitn=;
end;
run;
Either remove the variable from the SELECT statement.
select ;
when (upcase(visit)="SCREENING") avisitn = 10;
...
Or move the extra test into the OTHERWISE block.
...
when ("EARLY TERMINATION") avisitn = 100;
otherwise do;
if upcase(visit) =: "UNSCHEDULED" then avisitn =99;
else put "Check: " avisitn=;
end;
end;
Either remove the variable from the SELECT statement.
select ;
when (upcase(visit)="SCREENING") avisitn = 10;
...
Or move the extra test into the OTHERWISE block.
...
when ("EARLY TERMINATION") avisitn = 100;
otherwise do;
if upcase(visit) =: "UNSCHEDULED" then avisitn =99;
else put "Check: " avisitn=;
end;
end;
If the value is actually "UNSCHEDULED 1.01" why did you place "UNSCHEDULED" in the When?
You can get functions to work in When clauses but you need to change the Select as each expression has to be entered separately.
data example; input visit $18.; select ; when (upcase(visit)='DAY 1') avisitn=10; when (index(upcase(visit),"UNSCHEDULED")>0) avisitn =99; otherwise put "Check: " avisitn=; end; datalines; Day 1 unscheduled 1.01 ;
The argument of Select (<expression>) resolves the expression and the when is only looking for the result, so you can't mix value lists and expressions in When.
There can be multiple Unscheduled visits so not just 1.01 in the data but would all fall under the umbrella term of "UNSCHEDULED" per the mapping specifications
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.