Desktop productivity for business analysts and programmers

Condition to change a case in sas guide

Accepted Solution Solved
Reply
Contributor
Posts: 31
Accepted Solution

Condition to change a case in sas guide

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?

 

 


Accepted Solutions
Solution
‎08-11-2016 04:57 AM
Super User
Posts: 11,134

Re: Condition to change a case in sas guide

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


All Replies
Super User
Posts: 11,134

Re: Condition to change a case in sas guide

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.

Contributor
Posts: 31

Re: Condition to change a case in sas guide

@ballardw, hello is it good what I join?

Contributor
Posts: 31

Re: Condition to change a case in sas guide

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

Attachment
Solution
‎08-11-2016 04:57 AM
Super User
Posts: 11,134

Re: Condition to change a case in sas guide

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".

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 344 views
  • 0 likes
  • 2 in conversation