11-16-2011 04:42 AM
/*if id like 'na_%' then p=1;*/
where id like 'na_%' ;
i want if na_ like then to create new variable new_id=1
11-16-2011 06:13 AM
the comparison if id=: 'na_' (using the =: operator) will find those ID beginning 'na_' and reject ID= 'na-...' but it is not the same as the LIKE operator
'=:' compares the shorter of the two lengths so ID='n' would also satisfy the test ID =: 'na_'
To select only ID which begin 'na_' you could test just the first 3 characters with
substr( id, 1,3 ) = 'na_'
by the way, the LIKE operator treats '_' as a special indicator that any character must be present
where name like 'Ja_e__'
extracts 3 rows from sashelp.class - names Jane, James and Janet.
So some extra care is needed when _ needs to be treated as _ in a LIKE clause.
Check out ESCAPE in the "Syntax of WHERE Expression" at
11-23-2011 11:00 PM
You can't use the LIKE operator in this context (this operator is only for use in WHERE statements) - but you CAN use a PERL regular expression and the PRXMATCH function to accomplish the same thing:
data l2; set l; if prxmatch('/na_\w*/',id) then p=1; run;