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

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!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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';

View solution in original post

3 REPLIES 3
art297
Opal | Level 21

Is it a character or numeric field?

 

Art, CEO, AnalystFinder.com

Reeza
Super User

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';
art297
Opal | Level 21

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

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2955 views
  • 1 like
  • 3 in conversation