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

Hello,

 

My table is composed of "Centre Financier", which identifies the city where customers clients are traited.

On "date de bascule", il shows when the "Centre Financier" has changed.

 

The "Centre Financier " changes to " CF après bascule"  when these conditions are combined :

 

the 3 last numbers of  "numero de compte " are equal to "Code CF"

AND

the 2 first numbers of BGP are equal to "BGP begin"

AND  "date derniere maj operation" >= "date de bascule"

 

Can you help me we CASE / END solution please?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

SUBSTR does not accept negative numbers. Also your attempted syntax would have meant "start at position 1 and go back 2"

Here is an example of how to get the last 2 characters from a string using SUBSTR

data example;
   x= 'Some string of texz';
   y= substr(x,length(x)-1,2);
run;

This works by using the number of characters up to the last non-blank character. The LENGTH function would return the position of the Z in the example text. So we back up one position using -1 to get the position of the X. Then the 2 says to return 2 characters. This last may be needed if your string variable actually has trailing blanks though that isn't generally a concern if the only use is comparison as SAS will treat "33   " as equal to "33".

 

View solution in original post

4 REPLIES 4
ballardw
Super User

It helps if show a few records of input data and what the desired result looks like. Make sure the example shows at least one record for each type of issues. It helps if the example data is in the form of datastep code to provide something we can test code with.

peter2
Obsidian | Level 7

@ballardw, hello is it good what I join?

peter2
Obsidian | Level 7

@ballardw, I try to make a filter with SUBSTR on the last two caracters but it gives me nothing...is it the good code?

ballardw
Super User

SUBSTR does not accept negative numbers. Also your attempted syntax would have meant "start at position 1 and go back 2"

Here is an example of how to get the last 2 characters from a string using SUBSTR

data example;
   x= 'Some string of texz';
   y= substr(x,length(x)-1,2);
run;

This works by using the number of characters up to the last non-blank character. The LENGTH function would return the position of the Z in the example text. So we back up one position using -1 to get the position of the X. Then the 2 says to return 2 characters. This last may be needed if your string variable actually has trailing blanks though that isn't generally a concern if the only use is comparison as SAS will treat "33   " as equal to "33".

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 1043 views
  • 0 likes
  • 2 in conversation