- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Probably an easy task for a pro but I got stuck with this trivial problem for quite some time now:
I have this table as a start:
data inTable;
input ICD $ Drugs MDD ;
datalines;
F111 . .
F60 . .
F132 . .
F323 . .
F331 . .
;
I want to get the following results table:
data outtableDesired;
input ICD $ Drugs MDD ;
datalines;
F111 1.
F60 . .
F132 1 .
F323 . 1
F331 . 1
;
I tried the following:
data outtable;
set inTable;
if ICD in ('F11%','F13%') then do;
Drugs=1;
end;
if ICD in ('F32%','F33%') then do;
MDD=1;
end;
run;
Apparently '%' does not work in 'if ... then' procedures ... or? Any alternatives? Of course, my real table is much larger with many more options for ICD, that's why I have to write just the beginning of the character string and then '%'.
Thanks in advance for your time to help me with a solution!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi:
Are you trying to use the % as a wildcard? The % and the _ work with the LIKE operator in a WHERE statement or clause. You cannot use them in an IF statement.
But, if you are searching for F11 or F13 in the beginning of a string (so your full value is something like F11AB or F1134 or F13BC, then using the =: logical operator can work in an IF statement.
See this example.
Cynthia
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Shouldn't the syntax be
data outtable;
set inTable;
if ICD like ('F11%') or ICD like ('F13%') then do;
Drugs=1;
end;
run;
?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi:
Are you trying to use the % as a wildcard? The % and the _ work with the LIKE operator in a WHERE statement or clause. You cannot use them in an IF statement.
But, if you are searching for F11 or F13 in the beginning of a string (so your full value is something like F11AB or F1134 or F13BC, then using the =: logical operator can work in an IF statement.
See this example.
Cynthia
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, that's working well!
Hauke
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Note that the : modifier works with the IN operator also.
if code in: ('F11' 'F13') then .... ;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Good point!
Cynthia
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, that really makes it easier!
Hauke