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

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

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;
ballardw
Super User

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.

smackerz1988
Pyrite | Level 9

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 

smackerz1988
Pyrite | Level 9
Thanks! Appreciate the feedback!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 965 views
  • 3 likes
  • 3 in conversation