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 have this spec for ANRIND 

smackerz1988_0-1663262140324.png

 

 

Here is a sample of the data

 

data have;
input USUBJID $ LBSTNRC :$40. LBNRIND :$14. AVALC :$200.;
infile datalines dlm = '|';
datalines;
1001|Negative|NORMAL|Negative        
1001|5.0, 6.0, 7.0, 8.0|NORMAL|6.0
1001|5.0, 6.0, 7.0, 8.0|NORMAL|7.0
1001|5.0, 6.0, 7.0, 8.0|NORMAL|6.0
1001|Negative|ABNORMAL|5
1001|None, Occasional, 1-2|NORMAL|Occasional
1001|None, Occasional, 1-5|NORMAL|1-5                     
;

What is the best approach here? I know I could just do INDEX ,FIND, PRXCHANGE for matching but what is the best way to approach the comma separated variables and to make sure LBSTNRC and AVALC match and to account for the condition when they don't? 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Is AVALC ever more than that "one word" sort of appearance? If not, I don't understand the $200. input. If so, then you need to provide other examples of values of the AVALC variable.

 

My first feeling would be to use the FINDW function as you can specify the delimiter.

something like

 

if findw(lbstrnrc,strip(avalc),', ')>0 then <what you want to do when found>
else <what to do when not found>;

Strip is likely needed as you have defined AVALC as 200 characters in your example and would be looking for all 200 in the FINDW (or Find and Index or indexw functions)

Add in a Not missing(variable) to require the presence of a value where needed.

View solution in original post

2 REPLIES 2
ballardw
Super User

Is AVALC ever more than that "one word" sort of appearance? If not, I don't understand the $200. input. If so, then you need to provide other examples of values of the AVALC variable.

 

My first feeling would be to use the FINDW function as you can specify the delimiter.

something like

 

if findw(lbstrnrc,strip(avalc),', ')>0 then <what you want to do when found>
else <what to do when not found>;

Strip is likely needed as you have defined AVALC as 200 characters in your example and would be looking for all 200 in the FINDW (or Find and Index or indexw functions)

Add in a Not missing(variable) to require the presence of a value where needed.

smackerz1988
Pyrite | Level 9

Perfect thanks!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 833 views
  • 1 like
  • 2 in conversation