<?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: How to reformat a value using macro if, then, else. Can't get mine to produce correct results. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-a-value-using-macro-if-then-else-Can-t-get-mine/m-p/250368#M47210</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21089"&gt;@ncsthbell﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just use the single quotes only where you need them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If TYPE_CD (or NAICS_CD, resp.) typically contains a percent sign without single quotes, then the %IF condition in your macro should read &lt;FONT face="courier new,courier"&gt;&amp;amp;TYPE_CD=%&lt;/FONT&gt;. There is no need for additional quotes, because in macro language text processing is the default.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the data step, however, you should write the condition as &lt;FONT face="courier new,courier"&gt;"&amp;amp;TYPE_CD"="%"&lt;/FONT&gt; (or equivalently &lt;FONT face="courier new,courier"&gt;"&amp;amp;TYPE_CD"='%'&lt;/FONT&gt;), because a "naked" percent sign is not an appropriate character value in a data step.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Currently you add single quotes (and, in the %ELSE/ELSE branch, an additional percent sign) to whatever TYPE_CD &lt;SPAN&gt;(or NAICS_CD)&amp;nbsp;&lt;/SPAN&gt;contains. So, you would &lt;U&gt;not&lt;/U&gt; "leave variable as is."&lt;/P&gt;</description>
    <pubDate>Tue, 16 Feb 2016 16:12:24 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2016-02-16T16:12:24Z</dc:date>
    <item>
      <title>How to reformat a value using macro if, then, else. Can't get mine to produce correct results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-a-value-using-macro-if-then-else-Can-t-get-mine/m-p/250348#M47199</link>
      <description>&lt;P&gt;I have the following code in my program and it is returning the value of '%%' (the else condition) when it should be returning the value of '%'.&amp;nbsp; What am I doing wrong?&lt;/P&gt;
&lt;PRE&gt;%LET TYPE_CD = %; 

%macro TYPECD;
%if &amp;amp;TYPE_CD = '%' %then
   call symput("NEW_TYPE_CD","'"||"&amp;amp;TYPE_CD"||"'");   /*leave variable as is*/
%else call symput("NEW_TYPE_CD","'"||"&amp;amp;TYPE_CD"||"%'"); /wrap with %
%mend TYPECD;

&lt;/PRE&gt;
&lt;P&gt;NEW_TYPE_CD is returning value of '%%', should be '%'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TYPE_CD is defined in SMC as a prompt with default value of '%'&lt;/P&gt;
&lt;P&gt;If user leaves default, I want to select all type codes, so format is '%'.&lt;/P&gt;
&lt;P&gt;If user enters '722', I want to format as '722%' to select all type_cds that begin with '722'.&lt;/P&gt;
&lt;P&gt;I am trying to assign these values in the macro.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2016 15:19:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-a-value-using-macro-if-then-else-Can-t-get-mine/m-p/250348#M47199</guid>
      <dc:creator>ncsthbell</dc:creator>
      <dc:date>2016-02-16T15:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to reformat a value using macro if, then, else. Can't get mine to produce correct results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-a-value-using-macro-if-then-else-Can-t-get-mine/m-p/250356#M47203</link>
      <description>&lt;P&gt;This if fails:&lt;/P&gt;
&lt;PRE&gt;%if &amp;amp;TYPE_CD = '%' %then&lt;/PRE&gt;
&lt;P&gt;as: if % = '%' is not true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then this gets called:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%else call symput("NEW_TYPE_CD","'"||"&amp;amp;TYPE_CD"||"%'");&lt;/PRE&gt;
&lt;P&gt;becomes:&lt;/P&gt;
&lt;P&gt;else call symput("NEW_TYPE_CD","'"||"%"||"%'");&lt;/P&gt;
&lt;P&gt;As you have the macro parameter between double quotes, i.e. it dereferences at that point.&lt;/P&gt;
&lt;P&gt;Personally I wouldn't do this this way at all, what is the problem with using basic datastep code?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2016 15:31:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-a-value-using-macro-if-then-else-Can-t-get-mine/m-p/250356#M47203</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-02-16T15:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to reformat a value using macro if, then, else. Can't get mine to produce correct results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-a-value-using-macro-if-then-else-Can-t-get-mine/m-p/250361#M47207</link>
      <description>&lt;P&gt;I had the following in a data step first and got errors on this as well. I changed it to use a macro to see if I could get it to work.&amp;nbsp; I agree that data step is best way... just couldn't get it to work.&amp;nbsp; As you can tell, I do not have a lot of experience with SAS code.&lt;/P&gt;
&lt;P&gt;Here is what I had in Data step:&lt;/P&gt;
&lt;PRE&gt;data _null_;
/* build new prompt columns to use wildcard */
if &amp;amp;NAICS_CD = '%' then call symput('NEW_NAICS_CD',"'"||"&amp;amp;NAICS_CD"||"'");
else call symput('NEW_NAICS_CD',"'"||"&amp;amp;NAICS_CD"||"%'");
RUN;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error says:&lt;/P&gt;
&lt;P&gt;59&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data _null_;&lt;/P&gt;
&lt;P&gt;60&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* build new prompt columns to use wildcard */&lt;/P&gt;
&lt;P&gt;61&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if &amp;amp;NAICS_CD = '%' then call symput('NEW_NAICS_CD',"'"||"&amp;amp;NAICS_CD"||"'");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ____&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 180&lt;/P&gt;
&lt;P&gt;ERROR: Undeclared array referenced: symput.&lt;/P&gt;
&lt;P&gt;61&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if &amp;amp;NAICS_CD = '%' then call symput('NEW_NAICS_CD',"'"||"&amp;amp;NAICS_CD"||"'");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: +, =.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2016 15:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-a-value-using-macro-if-then-else-Can-t-get-mine/m-p/250361#M47207</guid>
      <dc:creator>ncsthbell</dc:creator>
      <dc:date>2016-02-16T15:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to reformat a value using macro if, then, else. Can't get mine to produce correct results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-a-value-using-macro-if-then-else-Can-t-get-mine/m-p/250365#M47209</link>
      <description>&lt;P&gt;What does&amp;nbsp;&lt;SPAN&gt;&amp;amp;NAICS_CD resoves to?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Use OPTIONS SYMBOLGEN;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2016 15:58:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-a-value-using-macro-if-then-else-Can-t-get-mine/m-p/250365#M47209</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-02-16T15:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to reformat a value using macro if, then, else. Can't get mine to produce correct results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-a-value-using-macro-if-then-else-Can-t-get-mine/m-p/250368#M47210</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21089"&gt;@ncsthbell﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just use the single quotes only where you need them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If TYPE_CD (or NAICS_CD, resp.) typically contains a percent sign without single quotes, then the %IF condition in your macro should read &lt;FONT face="courier new,courier"&gt;&amp;amp;TYPE_CD=%&lt;/FONT&gt;. There is no need for additional quotes, because in macro language text processing is the default.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the data step, however, you should write the condition as &lt;FONT face="courier new,courier"&gt;"&amp;amp;TYPE_CD"="%"&lt;/FONT&gt; (or equivalently &lt;FONT face="courier new,courier"&gt;"&amp;amp;TYPE_CD"='%'&lt;/FONT&gt;), because a "naked" percent sign is not an appropriate character value in a data step.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Currently you add single quotes (and, in the %ELSE/ELSE branch, an additional percent sign) to whatever TYPE_CD &lt;SPAN&gt;(or NAICS_CD)&amp;nbsp;&lt;/SPAN&gt;contains. So, you would &lt;U&gt;not&lt;/U&gt; "leave variable as is."&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2016 16:12:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-a-value-using-macro-if-then-else-Can-t-get-mine/m-p/250368#M47210</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-02-16T16:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to reformat a value using macro if, then, else. Can't get mine to produce correct results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-a-value-using-macro-if-then-else-Can-t-get-mine/m-p/250386#M47212</link>
      <description>&lt;P&gt;Yes, you have to remember that the macro pre-processor is basically an advanced text find/replace. &amp;nbsp;So take your code and resolve it yourself, it looks like:&lt;/P&gt;
&lt;PRE&gt;data _null_;
/* build new prompt columns to use wildcard */
if % = '%' then call symput('NEW_NAICS_CD',"'"||"%"||"'");
else call symput('NEW_NAICS_CD',"'"||"%"||"%'");
RUN;&lt;/PRE&gt;
&lt;P&gt;Maybe post an example of what you have and what you want, as from your code it looks like you want the text from &amp;amp;NAIS_CD followed by %, so something like:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  if strip("&amp;amp;NAICS_CD.")='%' then call symput('NEW_NAICS_CD',"'%'");
  else call symput('NEW_NAICS_CD',cats("'","&amp;amp;NAICS_CD","%'");
run;&lt;/PRE&gt;
&lt;P&gt;Now if &amp;amp;NAIS_CD. resolves to %, then &amp;amp;NEW_NAICS_CD. will resolve to '%' otherwise it will resolve to the text in &amp;amp;NAICS_CD. with the text % in single quotes (so for example if ABC: 'ABC%').&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2016 17:02:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-a-value-using-macro-if-then-else-Can-t-get-mine/m-p/250386#M47212</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-02-16T17:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to reformat a value using macro if, then, else. Can't get mine to produce correct results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-a-value-using-macro-if-then-else-Can-t-get-mine/m-p/250399#M47214</link>
      <description>&lt;P&gt;Thanks so much RW9.... your example was exactly what I needed it to do!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2016 17:36:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-a-value-using-macro-if-then-else-Can-t-get-mine/m-p/250399#M47214</guid>
      <dc:creator>ncsthbell</dc:creator>
      <dc:date>2016-02-16T17:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to reformat a value using macro if, then, else. Can't get mine to produce correct results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-a-value-using-macro-if-then-else-Can-t-get-mine/m-p/250411#M47215</link>
      <description>&lt;P&gt;You will find it much easier to not use % in that way in your input macro variables. &amp;nbsp;Since % is a macro trigger it can cause trouble.&lt;/P&gt;
&lt;P&gt;Why not just tell the users to use *, which is not a macro trigger, and then when you generate the value that you want to use in your LIKE condition you can replace the * with %.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   call symputx('new_type_cd',catq('1at',translate(symget('type_cd','%','*')));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Feb 2016 18:19:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-a-value-using-macro-if-then-else-Can-t-get-mine/m-p/250411#M47215</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-02-16T18:19:15Z</dc:date>
    </item>
  </channel>
</rss>

