Hi! I have a variable (concurrentcrg)..and I need to flag all the observations with values that start with 5 but do not end in 1.
Here the line of code that did not work...
if concurrentcrg in: ('5') and concurrentcrg ne '%1' then status='Uncontrolled';
Help is appreciated!
If character field, look at the SUBSTR() function.
If numeric field look at the SUBSTRN() function.
The REVERSE() function will reverse a string so you can obtain the last character. Or you could use the LENGTH function to get the last character.
Since it looks character, consider using the reverse function.
if substr(char, 1,1) = '5' and substr(trim(reverse(char)), 1,1) ne '1' then status='Uncontrolled';
Is it a character or numeric field?
Art, CEO, AnalystFinder.com
If character field, look at the SUBSTR() function.
If numeric field look at the SUBSTRN() function.
The REVERSE() function will reverse a string so you can obtain the last character. Or you could use the LENGTH function to get the last character.
Since it looks character, consider using the reverse function.
if substr(char, 1,1) = '5' and substr(trim(reverse(char)), 1,1) ne '1' then status='Uncontrolled';
Assuming it's character, then:
data want; set have; if first(concurrentcrg) eq '5' and first(reverse(strip(concurrentcrg))) ne '1' then status='Uncontrolled'; run;
Art, CEO, AnalystFinder.com
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.