<?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 Re: Macro Function using data Variable in Proc SQL or Data Step in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388656#M25060</link>
    <description>&lt;P&gt;My apologies Ballard. Rookie mistake.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am updating the code with sample data and will load again with Log Information in a couple moments.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Aug 2017 22:41:54 GMT</pubDate>
    <dc:creator>rahulp</dc:creator>
    <dc:date>2017-08-16T22:41:54Z</dc:date>
    <item>
      <title>Macro Function using data Variable in Proc SQL or Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388649#M25057</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need assistance with an issue I am unable to find a solution for. Below are the Macro and sample Data Step I have.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro exception(finish);
	%do i=%substr(&amp;amp;finish, %length(&amp;amp;finish), 1) %to %eval(%substr(&amp;amp;finish, %length(&amp;amp;finish), 1)+1);
		%let i=%eval(&amp;amp;i+1);
		%put %substr(&amp;amp;finish, 1, %eval(%length(&amp;amp;finish)-1))&amp;amp;i;
	%end;
%mend;
&lt;BR /&gt;/*Macro would increment the Tier by 1, the condition in DataStep is true*/

proc sql;
	create table data_in (
		STUDENT_NO 		NUM(8),
		TEST_SCORE 		NUM(20),
		TIER	   		CHAR(50),
		EXCEPTION_CD	CHAR(10)
		);


	insert into data_in (STUDENT_NO, TEST_SCORE, TIER, EXCEPTION_CD)
	values(1, 70, 'Tier_3', '')
	values(2, 80, 'Tier_2', '8')
	values(3, 90, 'Tier_1', '8')
	values(4, 65, 'Tier_0', '')
	;
quit;

data data_in;
set data_in;
select (EXCEPTION_CD);
   when ('8')        		EXCEPTION_TIER = %exception(TIER);
   otherwise                EXCEPTION_TIER = TIER;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the LOG with Errors:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;50            when ('8')        		EXCEPTION_TIER = %exception(TIER);
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 
       %substr(&amp;amp;finish, %length(&amp;amp;finish), 1) 
ERROR: The %FROM value of the %DO I loop is invalid.
50            when ('8')        		EXCEPTION_TIER = %exception(TIER);
                                                                   _
                                                                   22
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, 
              a missing value, INPUT, PUT.  

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 
       R+1 
ERROR: %EVAL function has no expression to evaluate, or %IF statement has no condition.
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro EXCEPTION will stop executing.&lt;/PRE&gt;&lt;P&gt;The out I desire:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;STUDENT_NO&lt;/TD&gt;&lt;TD&gt;TEST_SCORE&lt;/TD&gt;&lt;TD&gt;TIER&lt;/TD&gt;&lt;TD&gt;EXCEPTION_CD&lt;/TD&gt;&lt;TD&gt;EXCEPTION_TIER&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;70&lt;/TD&gt;&lt;TD&gt;Tier_3&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Tier_3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;80&lt;/TD&gt;&lt;TD&gt;Tier_2&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;Tier_3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;90&lt;/TD&gt;&lt;TD&gt;Tier_1&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;Tier_2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;65&lt;/TD&gt;&lt;TD&gt;Tier_0&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Tier_0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Any solution would be helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RV.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 22:52:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388649#M25057</guid>
      <dc:creator>rahulp</dc:creator>
      <dc:date>2017-08-16T22:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function using data Variable in Proc SQL or Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388651#M25058</link>
      <description>&lt;P&gt;1) there is no example data, we do not have your test.datain data set.&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) you apparently have a number of macro variables that we have no idea what values they may have. I suppose they are hidden in the %include file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) What help are you asking for? What is this code supposed to do? Do you get errors? Post code an log. Since this involves a macro you should probably have the options mprint symbolgen; on before running the macro. Post the log in a code box opened with the forum {i} menu icon to keep the format of any warning or error messages.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 22:30:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388651#M25058</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-16T22:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function using data Variable in Proc SQL or Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388653#M25059</link>
      <description>&lt;P&gt;From the documentation&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388649#M25057" target="_blank"&gt;https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388649#M25057&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="n11met8mb7xlpnn1gjtfriadf1gp" class="xis-tip"&gt;
&lt;DIV class="xis-tipGenText"&gt;Tip&lt;/DIV&gt;
The following example uses the %NRSTR macro quoting function to mask the macro statement. This function will delay the execution of macro statements until after a step boundary.
&lt;PRE class="xis-codeFragment"&gt;call execute('%nrstr(%sales('||month||'))');&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 22:35:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388653#M25059</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-08-16T22:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function using data Variable in Proc SQL or Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388656#M25060</link>
      <description>&lt;P&gt;My apologies Ballard. Rookie mistake.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am updating the code with sample data and will load again with Log Information in a couple moments.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 22:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388656#M25060</guid>
      <dc:creator>rahulp</dc:creator>
      <dc:date>2017-08-16T22:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function using data Variable in Proc SQL or Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388682#M25062</link>
      <description>&lt;P&gt;I don't think you need a macro in this setting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code below uses the SCAN() function to grab the&amp;nbsp;number&amp;nbsp;in TIER&amp;nbsp;after the underscore, uses the input() function to convert it from a character value to a numeric value, adds one to that value, and then uses the CATS function to concatentate that value onto "Tier_".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set data_in;
select (EXCEPTION_CD);
   when ('8')  EXCEPTION_TIER = cats("Tier_",input(scan(Tier,2,'_'),1.)+1);
   otherwise   EXCEPTION_TIER = TIER;
end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Aug 2017 02:50:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388682#M25062</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2017-08-17T02:50:49Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function using data Variable in Proc SQL or Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388787#M25074</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;Thanks for the response. However, I do need this in a Macro Function. The Value "Tier_" in your CATS, is dynamic and can and will change. NOOB Data: I have multiple Programs in a Project, and the final programs will reference this Macro (Global) to identify if there is an exception, and depending on the either the SELECT; DATA STEP or CASE PROC SQL Statement, create an Exception Tier.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope that clarified.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the response none the less.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2017 13:37:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388787#M25074</guid>
      <dc:creator>rahulp</dc:creator>
      <dc:date>2017-08-17T13:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function using data Variable in Proc SQL or Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388794#M25076</link>
      <description>&lt;P&gt;Sorry, I'm having a hard time understanding what you are trying to do.&amp;nbsp;&amp;nbsp;Macro issues aside, does the code I posted give you the output you would want for the sample data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, what parts of the code do you want to make dynamic, just the word Tier?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, then perhaps a macro like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro exception(finish);
  cats("&amp;amp;finish._",input(scan(&amp;amp;finish,2,'_'),1.)+1)
%mend exception;

data want;
set data_in;
select (EXCEPTION_CD);
   when ('8')  EXCEPTION_TIER = %exception(Tier);
   otherwise   EXCEPTION_TIER = TIER;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2017 13:47:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388794#M25076</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2017-08-17T13:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function using data Variable in Proc SQL or Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388812#M25077</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;Exactly what I wanted. So pretty much, my Macro was incorrect. What you provided, does what I need the Macro to do.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Much Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;. Marking post as answered.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2017 14:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388812#M25077</guid>
      <dc:creator>rahulp</dc:creator>
      <dc:date>2017-08-17T14:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function using data Variable in Proc SQL or Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388851#M25080</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;Probably marked this as a solution too soon. Still do need your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your solution works, however, what it actually does for&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function"&gt;cats&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"&amp;amp;finish._"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;scan&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;finish&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'_'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;is when then &amp;nbsp;condition is true for&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;when &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'8'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;  &lt;SPAN class="token number"&gt;EX&lt;/SPAN&gt;CEPTION_TIER &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token macroname"&gt;%exception&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;Tier&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It uses the actual String "Tier" in the conditional Statement, instead of what is in the Variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For Example, one of the Tiers would be called &lt;STRONG&gt;Test_Tier_0&lt;/STRONG&gt;, and with satisfied condition, I should get &lt;STRONG&gt;Test_Tier_1&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your method provides me with &lt;STRONG&gt;Tier_1.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can create a new post, but don't want to pollute the forum with this request.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2017 15:29:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388851#M25080</guid>
      <dc:creator>rahulp</dc:creator>
      <dc:date>2017-08-17T15:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function using data Variable in Proc SQL or Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388871#M25081</link>
      <description>&lt;P&gt;Sorry, I'm losing the big picture.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you said the value "Tier" was dynamic, I thought you meant you wanted to be able to specify the text value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now I think you mean there will always be a variable named Tier, which has a value in it, and the end of value is an underscore followed by a number.&amp;nbsp; And when Exception_CD='8', you want to set Exception_Tier to have the same "base value" as Tier, with the numeric suffix incremented.&amp;nbsp; Is that right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So is it just that you need code&amp;nbsp;that will compute the below variable WANT from the variable HAVE?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Have         Want
Tier_2       Tier_3 
Tier_1       Tier_2 
Test_Tier_0  Test_Tier_1
Blah_6       Blah_7&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If so, then I think the process could be: find the base value of the HAVE variable (i.e. value up to the last underscore), find the value of the the numeric suffix, incrementthe value of the numeric suffix, write the WANT variable by concatenating the base value with the numeric suffix.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I'm back to thinking this does not need to be a macro, so maybe I'm not understanding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More details:&lt;/P&gt;
&lt;P&gt;1. Is there always an underscore in the value, and always a numeric suffix after the last underscore?&lt;/P&gt;
&lt;P&gt;2. Is the numeric suffix always between 0 and 8, or if not, what is the range of possible numeric suffixes?&lt;/P&gt;
&lt;P&gt;3. Wouldn't life be easier if you just permanently separated the alpha part of the Tier variable (with values like "Tier", "Test_Tier" etc) into one variable, and the numeric suffix into another variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, feel free to un-accept my earlier answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2017 16:30:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388871#M25081</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2017-08-17T16:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function using data Variable in Proc SQL or Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388929#M25085</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;I am attaching what I think now works and does what it should Obviously, it was not possible for the code below to work without your code and the correct answer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will still leave the working code below if anyone else wants to do what I am trying to do (which probably is odd as well lol). Feel free to try it and let me know if you think it is correct or can be improved.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;P.S. I am unable to use the SCAN for _ (underscore) as some Tiers could have multiples.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro exception(finish);
  %let len = length(&amp;amp;finish);
  cats(substr(&amp;amp;finish,1,&amp;amp;len-1),substr(&amp;amp;finish,&amp;amp;len)+1)
%mend exception;

proc sql;
	create table data_in (
		STUDENT_NO 		NUM(8),
		TEST_SCORE 		NUM(20),
		TIER	   		CHAR(50),
		EXCEPTION_CD	CHAR(10)
	);


	insert into data_in (STUDENT_NO, TEST_SCORE, TIER, EXCEPTION_CD)
	values(1, 70, 'Tier_3', ' ')
	values(2, 80, 'Test_Tier_2', '8')
	values(3, 90, 'Tier_1', '8')
	values(4, 65, 'Tier_0', ' ')
	;
quit;

data want;
set data_in;
select (EXCEPTION_CD);
   when ('8')  EXCEPTION_TIER = %exception(TIER);
   otherwise   EXCEPTION_TIER = TIER;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Aug 2017 18:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-using-data-Variable-in-Proc-SQL-or-Data-Step/m-p/388929#M25085</guid>
      <dc:creator>rahulp</dc:creator>
      <dc:date>2017-08-17T18:26:02Z</dc:date>
    </item>
  </channel>
</rss>

