<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Function Substr with OR in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Function-Substr-with-OR/m-p/39045#M4705</link>
    <description>Need help.....!!!&lt;BR /&gt;
&lt;BR /&gt;
I want  to classified data with function substr and sql procedure...&lt;BR /&gt;
&lt;BR /&gt;
This code can't solve my problem.....&lt;BR /&gt;
&lt;BR /&gt;
================================================&lt;BR /&gt;
proc sql;&lt;BR /&gt;
	create table Tas1 as&lt;BR /&gt;
	select a.*, b.CampName,b.ProdName&lt;BR /&gt;
	, case substr(a.Campaign, -5,3)&lt;BR /&gt;
		when 'JAN' then 1&lt;BR /&gt;
		when 'FEB' then 2&lt;BR /&gt;
		when 'MAR' then 3&lt;BR /&gt;
		when 'APR' then 4&lt;BR /&gt;
		when 'MAY' then 5&lt;BR /&gt;
		when 'JUN' then 6&lt;BR /&gt;
		when 'JUL' then 7&lt;BR /&gt;
		when 'AUG' then 8&lt;BR /&gt;
		when 'SEP' then 9&lt;BR /&gt;
		when 'OCT' then 10&lt;BR /&gt;
		when 'NOV' then 11&lt;BR /&gt;
		when 'DEC' then 12&lt;BR /&gt;
		else 0 end as mth&lt;BR /&gt;
	, case substr(b.MONTH, 1,3)&lt;BR /&gt;
		when 'JAN' then 1&lt;BR /&gt;
		when 'FEB' then 2&lt;BR /&gt;
		when 'MAR' then 3&lt;BR /&gt;
		when 'APR' then 4&lt;BR /&gt;
		when 'MAY' then 5&lt;BR /&gt;
		when 'JUN' then 6&lt;BR /&gt;
		when 'JUL' then 7&lt;BR /&gt;
		when 'AUG' then 8&lt;BR /&gt;
		when 'SEP' then 9&lt;BR /&gt;
		when 'OCT' then 10&lt;BR /&gt;
		when 'NOV' then 11&lt;BR /&gt;
		when 'DEC' then 12&lt;BR /&gt;
		else 0 end as mth ,&amp;amp;yy as year from Tas a left join ProductDef b on a.campaignid=b.CampId&lt;BR /&gt;
	where substr(b.CampName,1,1) ^="'" and ProdName ^="CANCEL";&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
or this....&lt;BR /&gt;
&lt;BR /&gt;
========================================================&lt;BR /&gt;
proc sql;&lt;BR /&gt;
	create table Tas1 as&lt;BR /&gt;
	select a.*, b.CampName,b.ProdName&lt;BR /&gt;
	, case substr(b.MONTH, -5,3) or substr(b.MONTH, 1,3)&lt;BR /&gt;
		when 'JAN' then 1&lt;BR /&gt;
		when 'FEB' then 2&lt;BR /&gt;
		when 'MAR' then 3&lt;BR /&gt;
		when 'APR' then 4&lt;BR /&gt;
		when 'MAY' then 5&lt;BR /&gt;
		when 'JUN' then 6&lt;BR /&gt;
		when 'JUL' then 7&lt;BR /&gt;
		when 'AUG' then 8&lt;BR /&gt;
		when 'SEP' then 9&lt;BR /&gt;
		when 'OCT' then 10&lt;BR /&gt;
		when 'NOV' then 11&lt;BR /&gt;
		when 'DEC' then 12&lt;BR /&gt;
		else 0 end as mth ,&amp;amp;yy as year from Tas a left join ProductDef b on a.campaignid=b.CampId&lt;BR /&gt;
	where substr(b.CampName,1,1) ^="'" and ProdName ^="CANCEL";&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
======================================&lt;BR /&gt;
&lt;BR /&gt;
anyone can help me......&lt;BR /&gt;
&lt;BR /&gt;
Thx a lot.....&lt;BR /&gt;
&lt;BR /&gt;
regards,&lt;BR /&gt;
&lt;BR /&gt;
Yadi Acho....</description>
    <pubDate>Wed, 24 Nov 2010 04:30:30 GMT</pubDate>
    <dc:creator>YadiAcho</dc:creator>
    <dc:date>2010-11-24T04:30:30Z</dc:date>
    <item>
      <title>Function Substr with OR</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Function-Substr-with-OR/m-p/39045#M4705</link>
      <description>Need help.....!!!&lt;BR /&gt;
&lt;BR /&gt;
I want  to classified data with function substr and sql procedure...&lt;BR /&gt;
&lt;BR /&gt;
This code can't solve my problem.....&lt;BR /&gt;
&lt;BR /&gt;
================================================&lt;BR /&gt;
proc sql;&lt;BR /&gt;
	create table Tas1 as&lt;BR /&gt;
	select a.*, b.CampName,b.ProdName&lt;BR /&gt;
	, case substr(a.Campaign, -5,3)&lt;BR /&gt;
		when 'JAN' then 1&lt;BR /&gt;
		when 'FEB' then 2&lt;BR /&gt;
		when 'MAR' then 3&lt;BR /&gt;
		when 'APR' then 4&lt;BR /&gt;
		when 'MAY' then 5&lt;BR /&gt;
		when 'JUN' then 6&lt;BR /&gt;
		when 'JUL' then 7&lt;BR /&gt;
		when 'AUG' then 8&lt;BR /&gt;
		when 'SEP' then 9&lt;BR /&gt;
		when 'OCT' then 10&lt;BR /&gt;
		when 'NOV' then 11&lt;BR /&gt;
		when 'DEC' then 12&lt;BR /&gt;
		else 0 end as mth&lt;BR /&gt;
	, case substr(b.MONTH, 1,3)&lt;BR /&gt;
		when 'JAN' then 1&lt;BR /&gt;
		when 'FEB' then 2&lt;BR /&gt;
		when 'MAR' then 3&lt;BR /&gt;
		when 'APR' then 4&lt;BR /&gt;
		when 'MAY' then 5&lt;BR /&gt;
		when 'JUN' then 6&lt;BR /&gt;
		when 'JUL' then 7&lt;BR /&gt;
		when 'AUG' then 8&lt;BR /&gt;
		when 'SEP' then 9&lt;BR /&gt;
		when 'OCT' then 10&lt;BR /&gt;
		when 'NOV' then 11&lt;BR /&gt;
		when 'DEC' then 12&lt;BR /&gt;
		else 0 end as mth ,&amp;amp;yy as year from Tas a left join ProductDef b on a.campaignid=b.CampId&lt;BR /&gt;
	where substr(b.CampName,1,1) ^="'" and ProdName ^="CANCEL";&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
or this....&lt;BR /&gt;
&lt;BR /&gt;
========================================================&lt;BR /&gt;
proc sql;&lt;BR /&gt;
	create table Tas1 as&lt;BR /&gt;
	select a.*, b.CampName,b.ProdName&lt;BR /&gt;
	, case substr(b.MONTH, -5,3) or substr(b.MONTH, 1,3)&lt;BR /&gt;
		when 'JAN' then 1&lt;BR /&gt;
		when 'FEB' then 2&lt;BR /&gt;
		when 'MAR' then 3&lt;BR /&gt;
		when 'APR' then 4&lt;BR /&gt;
		when 'MAY' then 5&lt;BR /&gt;
		when 'JUN' then 6&lt;BR /&gt;
		when 'JUL' then 7&lt;BR /&gt;
		when 'AUG' then 8&lt;BR /&gt;
		when 'SEP' then 9&lt;BR /&gt;
		when 'OCT' then 10&lt;BR /&gt;
		when 'NOV' then 11&lt;BR /&gt;
		when 'DEC' then 12&lt;BR /&gt;
		else 0 end as mth ,&amp;amp;yy as year from Tas a left join ProductDef b on a.campaignid=b.CampId&lt;BR /&gt;
	where substr(b.CampName,1,1) ^="'" and ProdName ^="CANCEL";&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
======================================&lt;BR /&gt;
&lt;BR /&gt;
anyone can help me......&lt;BR /&gt;
&lt;BR /&gt;
Thx a lot.....&lt;BR /&gt;
&lt;BR /&gt;
regards,&lt;BR /&gt;
&lt;BR /&gt;
Yadi Acho....</description>
      <pubDate>Wed, 24 Nov 2010 04:30:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Function-Substr-with-OR/m-p/39045#M4705</guid>
      <dc:creator>YadiAcho</dc:creator>
      <dc:date>2010-11-24T04:30:30Z</dc:date>
    </item>
    <item>
      <title>Re: Function Substr with OR</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Function-Substr-with-OR/m-p/39046#M4706</link>
      <description>In your PROC SQL and the SELECT, you can use a combination of string-constant data values concatenated with suitable input data substring, then run it through the appropriate INFORMAT.  Similar DATA step example listed below; also works with PROC SQL.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
26   data _null_;&lt;BR /&gt;
27   retain Campaign 'NOV....';&lt;BR /&gt;
28   month = month(input('01'!!SUBSTR(Campaign,1,3)!!'00',date.));&lt;BR /&gt;
29   putlog _all_;&lt;BR /&gt;
30   run;&lt;BR /&gt;
&lt;BR /&gt;
Campaign=NOV.... month=11 _ERROR_=0 _N_=1&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.00 seconds&lt;BR /&gt;
      cpu time            0.00 seconds</description>
      <pubDate>Wed, 24 Nov 2010 14:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Function-Substr-with-OR/m-p/39046#M4706</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-11-24T14:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: Function Substr with OR</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Function-Substr-with-OR/m-p/39047#M4707</link>
      <description>Thx a lot...&lt;BR /&gt;
&lt;BR /&gt;
But I can't understand what this input means.... you can tell me why using this...&lt;BR /&gt;
&lt;BR /&gt;
'01'!!...... !!'00'.....&lt;BR /&gt;
&lt;BR /&gt;
thx for your advice...&lt;BR /&gt;
&lt;BR /&gt;
Acho...</description>
      <pubDate>Tue, 30 Nov 2010 06:43:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Function-Substr-with-OR/m-p/39047#M4707</guid>
      <dc:creator>YadiAcho</dc:creator>
      <dc:date>2010-11-30T06:43:46Z</dc:date>
    </item>
    <item>
      <title>Re: Function Substr with OR</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Function-Substr-with-OR/m-p/39048#M4708</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
Some sample data would have been helpful...&lt;BR /&gt;
&lt;BR /&gt;
Below some code built on assumptions on how your data might look like.&lt;BR /&gt;
&lt;BR /&gt;
Why in first place do you query 2 fields to get the month number. &lt;BR /&gt;
Is this because "Campaign" could be missing? If so then the coalesce() function could be helpful.&lt;BR /&gt;
&lt;BR /&gt;
However: Below code is doing what I believe you had in mind - which doesn't mean it will give you the desired result... &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;  &lt;BR /&gt;
&lt;BR /&gt;
proc format;&lt;BR /&gt;
  invalue MonthNum&lt;BR /&gt;
   'JAN' = 1&lt;BR /&gt;
   'FEB' = 2&lt;BR /&gt;
   'MAR' = 3&lt;BR /&gt;
   'APR' = 4&lt;BR /&gt;
   'MAY' = 5&lt;BR /&gt;
   'JUN' = 6&lt;BR /&gt;
   'JUL' = 7&lt;BR /&gt;
   'AUG' = 8&lt;BR /&gt;
   'SEP' = 9&lt;BR /&gt;
   'OCT' = 10&lt;BR /&gt;
   'NOV' = 11&lt;BR /&gt;
   'DEC' = 12&lt;BR /&gt;
   otherwise = .&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
data Tas;&lt;BR /&gt;
  length Campaign $ 20;&lt;BR /&gt;
  do Campaign='JANUARY','MARCH','AUGUST','SEPTEMBER', 'NOVEMBER','DECEMBER';&lt;BR /&gt;
    campaignid+1;&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data ProductDef;&lt;BR /&gt;
  length month $ 20;&lt;BR /&gt;
  CampName='dummy';&lt;BR /&gt;
  ProdName='dummy';&lt;BR /&gt;
  do Month='FEBRUARY','APRIL','AUGUST','NOVEMBER';&lt;BR /&gt;
    CampId+1;&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
  Month='OCTOBER';&lt;BR /&gt;
  CampId=10;&lt;BR /&gt;
  output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%let yy=2010;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
/*create table Tas1 as*/&lt;BR /&gt;
  select &lt;BR /&gt;
    a.*, &lt;BR /&gt;
    b.month as ProductDef_Month,&lt;BR /&gt;
    b.CampName,&lt;BR /&gt;
    b.ProdName,&lt;BR /&gt;
    case&lt;BR /&gt;
      when input(substr(b.month,1,3),MonthNum.)    ne .  then input(substr(b.month,1,3),MonthNum.)&lt;BR /&gt;
      when input(substr(a.Campaign,1,3),MonthNum.) ne .  then input(substr(a.Campaign,1,3),MonthNum.)&lt;BR /&gt;
      else 0&lt;BR /&gt;
    end as mth,&lt;BR /&gt;
    &amp;amp;yy as year &lt;BR /&gt;
  from Tas a left join ProductDef b on a.campaignid=b.CampId&lt;BR /&gt;
  where substr(b.CampName,1,1) ^="'" and ProdName ^="CANCEL";&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
In regards to the code you've posted:&lt;BR /&gt;
- A substr() can't start at a minus position "-5"&lt;BR /&gt;
- A logical condition must be in the when and not in the case (it's like a SAS data step SELECT statement).&lt;BR /&gt;
- The code with the 2 case statements assigns the values to the same variable - you can't do this in SQL (and what result would you expect from this anyway?)&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Patrick

Message was edited by: Patrick</description>
      <pubDate>Tue, 30 Nov 2010 10:20:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Function-Substr-with-OR/m-p/39048#M4708</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-11-30T10:20:31Z</dc:date>
    </item>
  </channel>
</rss>

