<?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: SAS Macro Problem in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636921#M189295</link>
    <description>&lt;P&gt;Your code is not only overly complicated, it can NEVER work.&lt;/P&gt;
&lt;P&gt;You try to run a proc sql step inside a data step; this is not possible, the data step ends as soon as SAS sees the keyword PROC. This is very basic SAS knowledge, and since you do not have that yet, you should not waste your brain cycles with macro coding. Macro coding needs solid, in-depth knowledge of the SAS language to be of any use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once again: post your example data in usable form, and what you want to get out of it. A possible solution without any macro coding has already been posted.&lt;/P&gt;</description>
    <pubDate>Thu, 02 Apr 2020 16:07:56 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-04-02T16:07:56Z</dc:date>
    <item>
      <title>SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636892#M189280</link>
      <description>&lt;DIV class="F0XO1GC-ed-a"&gt;&lt;DIV class="F0XO1GC-nb-P"&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;I don't understand what is happening. &amp;nbsp;I'm no expert at the macro language, but I just don't understand what SAS is doing.&lt;BR /&gt;&lt;BR /&gt;I have a list of brands in a macro variable name1-name13 and am iterating through the list to see if the variable brand is equal to the brand that is being iterated on.&lt;BR /&gt;&lt;BR /&gt;%macro doit;&lt;BR /&gt;%do i=1 %to &amp;amp;NObs;&lt;BR /&gt;&amp;nbsp;%put # # # Processing &amp;amp;&amp;amp;Name&amp;amp;i # # #;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;%if brand = &amp;amp;&amp;amp;Name&amp;amp;i %then newvar=0 ; (this will actually do something else - this is just to test the comparison)&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%doit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Log file:&lt;BR /&gt;&lt;BR /&gt;MLOGIC(DOIT): &amp;nbsp;Beginning execution.&lt;BR /&gt;MLOGIC(DOIT): &amp;nbsp;%DO loop beginning; index variable I; start value is 1; stop value is 13; by value is 1. &amp;nbsp;&lt;BR /&gt;MLOGIC(DOIT): &amp;nbsp;%PUT # # # Processing &amp;amp;&amp;amp;Name&amp;amp;i # # #&lt;BR /&gt;# # # Processing Brand A # # #&lt;BR /&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;brand = &amp;amp;&amp;amp;Name&amp;amp;i&lt;BR /&gt;ERROR: The macro DOIT will stop executing.&lt;BR /&gt;&lt;BR /&gt;Why is &amp;amp;&amp;amp;Name&amp;amp;i resolving fine for the put statement, but not for the if then comparison line?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="F0XO1GC-ed-a"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="F0XO1GC-nb-b"&gt;&lt;DIV class="F0XO1GC-nb-a F0XO1GC-nb-cb"&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="F0XO1GC-md-a"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 02 Apr 2020 15:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636892#M189280</guid>
      <dc:creator>cougar300</dc:creator>
      <dc:date>2020-04-02T15:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636894#M189281</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;brand = &amp;amp;&amp;amp;Name&amp;amp;i %then %let newvar=0 ;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you are doing macro variable comparisons, then you need &amp;amp;BRAND. You also need %let.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 15:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636894#M189281</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-02T15:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636895#M189282</link>
      <description>&lt;P&gt;sorry if I didn't explain things clearly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a variable brand - it is not a macro variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially, I have a dataset that has a variable brand, then I have a variable named after each brand, and let's say I'm just trying to flag where the brand matches the variable (it's not that simple, but those are the cases in which I want to do something), so that the data I'm trying to get to is this (assuming the Brand variables are all zero to start):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BRAND&amp;nbsp; &amp;nbsp; &amp;nbsp;BRAND A&amp;nbsp; &amp;nbsp; &amp;nbsp;BRAND B&amp;nbsp; &amp;nbsp; &amp;nbsp;BRAND C&lt;/P&gt;&lt;P&gt;BRAND A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;BRAND B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;BRAND C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 15:29:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636895#M189282</guid>
      <dc:creator>cougar300</dc:creator>
      <dc:date>2020-04-02T15:29:57Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636901#M189285</link>
      <description>&lt;P&gt;In this scenario, do you have the Brand_A - Brand_C variables from the start or should they be created from the values of the variable Brand?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 15:39:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636901#M189285</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-04-02T15:39:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636904#M189286</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/320332"&gt;@cougar300&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;sorry if I didn't explain things clearly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a variable brand - it is not a macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Essentially, I have a dataset that has a variable brand, then I have a variable named after each brand, and let's say I'm just trying to flag where the brand matches the variable (it's not that simple, but those are the cases in which I want to do something), so that the data I'm trying to get to is this (assuming the Brand variables are all zero to start):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BRAND&amp;nbsp; &amp;nbsp; &amp;nbsp;BRAND A&amp;nbsp; &amp;nbsp; &amp;nbsp;BRAND B&amp;nbsp; &amp;nbsp; &amp;nbsp;BRAND C&lt;/P&gt;
&lt;P&gt;BRAND A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;BRAND B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;BRAND C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Maybe you should show us the full log so we can see all the code and all the warnings and error messages. It seems as if you are talking about using a macro to set the value of a data set variable, but you haven't shown us any data step code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 15:43:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636904#M189286</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-02T15:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636909#M189288</link>
      <description>&lt;P&gt;Using data step variables in macro conditions DOES NOT WORK. The macro condition is resolved before any data step code is compiled and later executed.&lt;/P&gt;
&lt;P&gt;There is a 90%+ chance that you do not need any macro processing for what you want to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having a variable for each brand value is &lt;U&gt;&lt;EM&gt;bad data design&lt;/EM&gt;&lt;/U&gt;; transpose to a long format, and your task will be MUCH easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get more help, post example data (your base and/or lookup datasets), in usable form (data step(s) with datalines), and the result you want to get out of it.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 15:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636909#M189288</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-02T15:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636910#M189289</link>
      <description>&lt;P&gt;It's not complicated code, it's just getting the macro variables to resolve properly that is the problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only line that needs to change is the if then line.&amp;nbsp; I started without the real THEN part because I can't get the IF comparison to work, but I'm sure the second part will be a problem as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data notes: There are spaces in the brand names, so the variable names have spaces in them.&amp;nbsp; This works:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if brand = 'A/O Stuff' then 'A/O Stuff'n =1; so I'm wondering if the THEN part will need to be "&amp;amp;&amp;amp;Name&amp;amp;i."n or some such, but I can't get past the IF evaluating correctly at this point.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data dataset8;&lt;BR /&gt;set dataset7;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select count(*)&lt;BR /&gt;into :NObs&lt;BR /&gt;from brandlist;&lt;BR /&gt;select brand&lt;BR /&gt;into :Name1-:Name%left(&amp;amp;NObs)&lt;BR /&gt;from brandlist&lt;BR /&gt;quit;&lt;BR /&gt;%macro doit;&lt;BR /&gt;%do i=1 %to &amp;amp;NObs;&lt;BR /&gt;%put # # # Processing &amp;amp;&amp;amp;Name&amp;amp;i # # #;&lt;/P&gt;&lt;P&gt;%if brand = &amp;amp;&amp;amp;Name&amp;amp;i %then &amp;amp;&amp;amp;Name&amp;amp;i = 1 ;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%doit;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;log:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;26 proc sql noprint;&lt;/P&gt;&lt;P&gt;27 select count(*)&lt;BR /&gt;28 into :NObs&lt;BR /&gt;29 from brandlist/*SAShelp.class*/;&lt;BR /&gt;30 select brand&lt;BR /&gt;31 into :Name1-:Name%left(&amp;amp;NObs)&lt;BR /&gt;MLOGIC(LEFT): Beginning execution.&lt;BR /&gt;MLOGIC(LEFT): This macro was compiled from the autocall file /ix1521/SAS94M5/sashome/SASFoundation/9.4/sasautos/left.sas&lt;BR /&gt;MLOGIC(LEFT): Parameter TEXT has value 13&lt;BR /&gt;MLOGIC(LEFT): %LOCAL I&lt;BR /&gt;2 The SAS System 09:30 Thursday, April 2, 2020&lt;/P&gt;&lt;P&gt;MLOGIC(LEFT): %IF condition %length(&amp;amp;text)=0 is FALSE&lt;BR /&gt;MLOGIC(LEFT): %LET (variable name is I)&lt;BR /&gt;MLOGIC(VERIFY): Beginning execution.&lt;BR /&gt;MLOGIC(VERIFY): This macro was compiled from the autocall file /ix1521/SAS94M5/sashome/SASFoundation/9.4/sasautos/verify.sas&lt;BR /&gt;MLOGIC(VERIFY): Parameter TEXT has value 13&lt;BR /&gt;MLOGIC(VERIFY): Parameter TARGET has value &amp;#1; &amp;#2;&lt;BR /&gt;MLOGIC(VERIFY): %LOCAL I&lt;BR /&gt;MLOGIC(VERIFY): %IF condition %length(&amp;amp;text)=0 OR %length(&amp;amp;target)=0 is FALSE&lt;BR /&gt;MLOGIC(VERIFY): %DO loop beginning; index variable I; start value is 1; stop value is 2; by value is 1.&lt;BR /&gt;MLOGIC(VERIFY): %IF condition NOT %index(&amp;amp;target,%qsubstr(&amp;amp;text,&amp;amp;i,1)) is TRUE&lt;BR /&gt;MLOGIC(VERIFY): %GOTO VERFND (label resolves to VERFND).&lt;BR /&gt;MLOGIC(VERIFY): %IF condition &amp;amp;i&amp;gt;%length(&amp;amp;text) is FALSE&lt;BR /&gt;MLOGIC(VERIFY): Ending execution.&lt;BR /&gt;MLOGIC(LEFT): %IF condition &amp;amp;i is TRUE&lt;BR /&gt;MPRINT(LEFT): Name13&lt;BR /&gt;MLOGIC(LEFT): Ending execution.&lt;BR /&gt;32 from brandlist/*SAShelp.class*/;&lt;BR /&gt;33 quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;user cpu time 0.00 seconds&lt;BR /&gt;system cpu time 0.00 seconds&lt;BR /&gt;memory 5429.18k&lt;BR /&gt;OS Memory 26024.00k&lt;BR /&gt;Timestamp 04/02/2020 11:25:52 AM&lt;BR /&gt;Step Count 115 Switch Count 0&lt;BR /&gt;Page Faults 0&lt;BR /&gt;Page Reclaims 15&lt;BR /&gt;Page Swaps 0&lt;BR /&gt;Voluntary Context Switches 3&lt;BR /&gt;Involuntary Context Switches 0&lt;BR /&gt;Block Input Operations 0&lt;BR /&gt;Block Output Operations 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;34 %macro doit;&lt;BR /&gt;35 %do i=1 %to &amp;amp;NObs;&lt;BR /&gt;36 %put # # # Processing &amp;amp;&amp;amp;Name&amp;amp;i # # #;&lt;BR /&gt;37&lt;BR /&gt;38 %if brand = &amp;amp;&amp;amp;Name&amp;amp;i %then %let newvar=0 ;&lt;BR /&gt;39&amp;nbsp;&lt;BR /&gt;40 %end;&lt;BR /&gt;41 %mend;&lt;BR /&gt;42 %doit;&lt;BR /&gt;MLOGIC(DOIT): Beginning execution.&lt;BR /&gt;MLOGIC(DOIT): %DO loop beginning; index variable I; start value is 1; stop value is 13; by value is 1.&lt;BR /&gt;MLOGIC(DOIT): %PUT # # # Processing &amp;amp;&amp;amp;Name&amp;amp;i # # #&lt;BR /&gt;# # # Processing A/O Stuff # # #&lt;BR /&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:&lt;BR /&gt;brand = &amp;amp;&amp;amp;Name&amp;amp;i&lt;BR /&gt;ERROR: The macro DOIT will stop executing.&lt;BR /&gt;MLOGIC(DOIT): Ending execution.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 15:51:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636910#M189289</guid>
      <dc:creator>cougar300</dc:creator>
      <dc:date>2020-04-02T15:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636913#M189291</link>
      <description>&lt;P&gt;Oh, and to the other question, the brand variables are already there with 0 in all entries.&amp;nbsp; I don't need to create these variables, that's already been done in an earlier step.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 15:52:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636913#M189291</guid>
      <dc:creator>cougar300</dc:creator>
      <dc:date>2020-04-02T15:52:28Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636914#M189292</link>
      <description>&lt;P&gt;Sounds like you have this data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id brand $20.;
cards;
1 Brand A
2 Brand B
3 Brand C
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And you want to run this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  brand_a = brand='Brand A';
  brand_b = brand='Brand B';
  brand_c = brand='Brand C';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can play around with figuring out how to get macro code to generate that SAS code.&lt;/P&gt;
&lt;P&gt;But perhaps it is easier to just use SAS code instead of monkeying around with macro code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step1;
  set have;
  dummy=1;
run;
proc transpose data=step1 out=step2(drop=_name_);
  by id brand;
  id brand;
  var dummy;
run;
proc stdize data=step2 out=want reponly missing=0;
run;
proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    id     brand     Brand_A    Brand_B    Brand_C

 1      1    Brand A       1          0          0
 2      2    Brand B       0          1          0
 3      3    Brand C       0          0          1&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 15:52:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636914#M189292</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-02T15:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636915#M189293</link>
      <description>&lt;P&gt;%IF &amp;lt;data set varaible name&amp;gt; is almost never going to do what you want. &lt;BR /&gt;First you must have the macro called inside a data step or procedure that defines the data set with the variables (nothing related to this shown in your example)&lt;/P&gt;
&lt;P&gt;Second the Macro elements would process before the data step or procedure attempts to execute and would create code lines, but not comparing the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are attempting to compare a variable in a data step to a macro variable then assign a value to a different data step variable the code would would look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if var =&amp;amp;macrovar. then newvar = 0;&lt;/P&gt;
&lt;P&gt;If the value is a character value then you would place the macro variable inside double quotes:&lt;/P&gt;
&lt;P&gt;if var = "&amp;amp;macrovar." then newvar =0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Options MPRINT may be more useful in this case then Mlogic.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 15:52:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636915#M189293</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-02T15:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636919#M189294</link>
      <description>&lt;P&gt;Your code is mixed up. You have a data step that does nothing other than duplicate the data. Then an SQL step and the macro code that is not generating any valid SAS code at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's clean up the SQL step first.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select distinct quote(trim(brand)),nliteral(brand)
    into :brands1-,:names1-
    from brandlist
  ;
%let nobs=&amp;amp;sqlobs;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now we can use those macro variables to generate SAS code (let's assume you have wrapped it into a macro definition so we can use macro logic).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have;
%do index=1 %to &amp;amp;nobs;
  &amp;amp;&amp;amp;names&amp;amp;index = (brand = &amp;amp;&amp;amp;brands&amp;amp;index);
%end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the values are really messy then don't use them for variable names. Just use numbers and put the values into the label of the variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select distinct quote(trim(brand))
    into :brands1-
    from brandlist
  ;
%let nobs=&amp;amp;sqlobs;
quit;
data want ;
  set have;
%do index=1 %to &amp;amp;nobs;
   brand&amp;amp;index = (brand = &amp;amp;&amp;amp;brands&amp;amp;index);
   label brand&amp;amp;index = &amp;amp;&amp;amp;brands&amp;amp;index ;
%end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Apr 2020 16:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636919#M189294</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-02T16:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636921#M189295</link>
      <description>&lt;P&gt;Your code is not only overly complicated, it can NEVER work.&lt;/P&gt;
&lt;P&gt;You try to run a proc sql step inside a data step; this is not possible, the data step ends as soon as SAS sees the keyword PROC. This is very basic SAS knowledge, and since you do not have that yet, you should not waste your brain cycles with macro coding. Macro coding needs solid, in-depth knowledge of the SAS language to be of any use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once again: post your example data in usable form, and what you want to get out of it. A possible solution without any macro coding has already been posted.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 16:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636921#M189295</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-02T16:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636925#M189296</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/320332"&gt;@cougar300&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Oh, and to the other question, the brand variables are already there with 0 in all entries.&amp;nbsp; I don't need to create these variables, that's already been done in an earlier step.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then you probably went haring off in the wrong direction there. It's a common problem we see with SAS newbies here who still think in Excel spreadsheets. Data (company names) does not belong in structure (variable names).&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 16:11:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636925#M189296</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-02T16:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636936#M189300</link>
      <description>&lt;P&gt;These have all been helpful replies, but maybe I'm getting too far into the weeds.&amp;nbsp; What I was asking was one piece of how I was going to solve this.&lt;/P&gt;&lt;P&gt;Let me back up a step.&lt;/P&gt;&lt;P&gt;I want to start with the data in yellow and have it end up adding the data in blue as far as SAS goes, where the number in blue is the ratio multiplied by the variable to flip for the associated brand.&amp;nbsp; In Excel you'd flip the variable to the top then just multiply across, but it's not that simple in sas.&amp;nbsp; Maybe some SQL step could accomplish this, but I don't use SQL a lot either.&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="sas.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/37680iDD103CB65E7E8214/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sas.jpg" alt="sas.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BIG NOTE: This is data for one store, where I'm doing it for many stores&lt;/P&gt;&lt;P&gt;My plan was to create another var for each Brand where Brand A FLIP would be the green area (although creating that number may not be as easy as I was initially thinking, either).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="sas2.jpg" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/37686iDE7C33178E2BD7F1/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas2.jpg" alt="sas2.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So that to get the blue area, all I would need to do would be multiply the Green Column by the ratio variable.&lt;/P&gt;&lt;P&gt;Maybe I was headed down the wrong path with the initial methodology to begin with as far as process goes.&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;So let me change the question to - can I get from the yellow area to adding the blue area in the sas dataset without too much trouble?&amp;nbsp; Easiest method?&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 16:33:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636936#M189300</guid>
      <dc:creator>cougar300</dc:creator>
      <dc:date>2020-04-02T16:33:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636944#M189304</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/320332"&gt;@cougar300&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;DIV class="F0XO1GC-ed-a"&gt;
&lt;DIV class="F0XO1GC-nb-P"&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;Why is &amp;amp;&amp;amp;Name&amp;amp;i resolving fine for the put statement, but not for the if then comparison line?&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/320332"&gt;@cougar300&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While the main problems with your code have been pointed out already, let me just answer the above question: In the case of &lt;FONT face="courier new,courier"&gt;&amp;amp;&amp;amp;Name&amp;amp;i&lt;/FONT&gt; resolving to &lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;A/O Stuff&lt;/FONT&gt;&amp;nbsp;t&lt;/SPAN&gt;he reason was that the macro processor interpreted the slash in "&lt;FONT face="courier new,courier"&gt;A&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;/&lt;/STRONG&gt;&lt;/FONT&gt;O Stuff&lt;/FONT&gt;" as the &lt;EM&gt;division operator&lt;/EM&gt;, which is valid only with numeric operands, not with character operands such as &lt;FONT face="courier new,courier"&gt;A&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;O&lt;/FONT&gt;. This is what the error message "&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;A character operand was found in the %EVAL function or %IF condition where a numeric operand is required.&lt;/FONT&gt;" referred to. (This would not have occurred with&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&amp;amp;&amp;amp;Name&amp;amp;i&lt;/FONT&gt; resolving to &lt;FONT face="courier new,courier"&gt;Brand A&lt;/FONT&gt;, which is what your initial post suggested.) It is indeed somewhat confusing that the error message ("&lt;FONT face="courier new,courier"&gt;The condition was:&amp;nbsp;brand = &amp;amp;&amp;amp;Name&amp;amp;i&lt;/FONT&gt;") does not resolve the macro variable reference and thus hides the culprit (the slash in this case).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If the comparison made sense in an %IF condition, double quotes or macro quoting functions (such as %BQUOTE) would need to be applied in order to avoid the wrong interpretation of the slash.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 17:09:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636944#M189304</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-04-02T17:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636978#M189315</link>
      <description>&lt;P&gt;Photographs of data are impossible to copy and paste into code.&lt;/P&gt;
&lt;P&gt;If you want to combine N brands with M ratios then keep them in SEPARATE datasets.&amp;nbsp; Then combine them.&lt;/P&gt;
&lt;P&gt;For example if the source datasets are BRAND_LIST and RATIO_LIST then code would look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table want as 
select a.brand
     , b.ratio 
     , a.value * b.ratio as WANT
from brand_list a
   , ratio_list b
order by 1,2
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to make a REPORT that looks like your photograph then us PROC REPORT or PROC TABULATE.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 17:38:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636978#M189315</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-02T17:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636980#M189317</link>
      <description>&lt;P&gt;Data&amp;nbsp; not pictures. I'm not going to create data from pictures to write code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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 &amp;lt;&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 17:38:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636980#M189317</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-02T17:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636986#M189320</link>
      <description>&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the "/" making it attempting a numeric conversion makes sense.&amp;nbsp; That clarifies that part, at least.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 17:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636986#M189320</guid>
      <dc:creator>cougar300</dc:creator>
      <dc:date>2020-04-02T17:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636995#M189322</link>
      <description>&lt;P&gt;If anyone can easily turn this starting data into the blue part shown in the above picture, please let me know.&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;data WORK.start;&lt;BR /&gt;infile datalines dsd truncover delimiter=',';&lt;BR /&gt;input Brand:$8. Amount:32. Ratio:32.;&lt;BR /&gt;datalines;&lt;BR /&gt;Brand A,20,.4&lt;BR /&gt;Brand B,16,.5&lt;BR /&gt;Brand C,12,.25&lt;BR /&gt;Brand D,8,.25&lt;BR /&gt;Brand E,14,0&lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 18:09:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/636995#M189322</guid>
      <dc:creator>cougar300</dc:creator>
      <dc:date>2020-04-02T18:09:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/637002#M189324</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.start;
  infile datalines dsd truncover ;
  input Brand $ Amount Ratio ;
datalines;
Brand A,20,.4
Brand B,16,.5
Brand C,12,.25
Brand D,8,.25
Brand E,14,0
;
proc sql;
  create table want as 
  select a.brand,a.amount,a.ratio
       , b.brand as brand2,b.amount*a.ratio as new_amount
  from start a
     , start b
  ;
quit;
proc report data=want ;
  columns brand amount ratio new_amount,brand2;
  define brand / group;
  define amount / group;
  define ratio / group;
  define brand2 / across ' ';
  define new_amount / sum;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 601px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/37706iAD5BA3146B35D1D2/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 18:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Problem/m-p/637002#M189324</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-02T18:34:58Z</dc:date>
    </item>
  </channel>
</rss>

