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

I want to give a filter on columnOne in the where clause

I use the following code in SQL and I get what i want

but when I write the same code in proc sql there is no errors but my code is not returning any rows?

Please help!

where year =2019

and right(left(ColumnOne, 6), 2) = 'DB'

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Are you just trying to test if the value end with the letters DB?

where year =2019
  and ColumnOne like '%DB'

If you really had a need to extract the last two characters from a string then use the function mentioned in your subject line.

data want;
  set have ;
  last2 = substrn(ColumnOne,length(ColumnOne)-1));
run;

 

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

It would help to see a portion of the actual data of variable ColumnOne. Otherwise, how could we be sure what the problem is? We also need to see the YEAR variable.

 

Please follow these instructions to create SAS data step code for your data, please provide a portion of your data this way and not via any other method: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

 

So, a lot more information is needed here.

--
Paige Miller
USHAKS
Fluorite | Level 6

Thanks for the help

CHEMDB

MATHDBGS

PaigeMiller
Diamond | Level 26

We also need to see YEAR.

 

Please show this to us as a SAS data step, following these isntructions: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

Or perhaps show us the output of PROC CONTENTS, that will give us a clue.

--
Paige Miller
SASKiwi
PROC Star

Not sure what you are trying to do here but the LEFT and RIGHT functions in SAS only have one parameter, not two as in your example: https://documentation.sas.com/?docsetId=ds2ref&docsetTarget=n1j1jxao7prdsmn1f9hrjtkwc6ue.htm&docsetV...

 

Maybe - substr(ColumnOne, 5, 2) = 'DB';

Tom
Super User Tom
Super User

Are you just trying to test if the value end with the letters DB?

where year =2019
  and ColumnOne like '%DB'

If you really had a need to extract the last two characters from a string then use the function mentioned in your subject line.

data want;
  set have ;
  last2 = substrn(ColumnOne,length(ColumnOne)-1));
run;

 

USHAKS
Fluorite | Level 6

in the where clause this script worked.

AND( substr(ColumnOne,5,2) ='DB' OR ColumnOne like '%DB' )

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 794 views
  • 1 like
  • 4 in conversation