<?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: Data column does not display from the macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-column-does-not-display-from-the-macro/m-p/479927#M123950</link>
    <description>&lt;P&gt;Better would be to provide some example data and the calculations you need to do from those 2x2 tables. For example Proc Freq will do risks, risk differences, odds ratios and relative risks for 2x2 tables without much work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't want to use %if / %then/ %do inside a data step when manipulative values of data step variables. Also if you want to use a variables value in a data step&amp;nbsp;do &lt;STRONG&gt;not&lt;/STRONG&gt; place the macro code for the name&amp;nbsp;inside quotes.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if &amp;amp;comp._&amp;amp;target._result="Positive" then do;
   if Y_&amp;amp;target._result="Positive" then "result"=TP;
   else if Y_&amp;amp;target._result="Negative" then "result"=FN;
end;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second might be to consider coding text values lf "Positive" and "Negative" as 1 and 0. Use a custom format to assign desired display text as needed.&lt;/P&gt;</description>
    <pubDate>Fri, 20 Jul 2018 15:52:21 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-07-20T15:52:21Z</dc:date>
    <item>
      <title>Data column does not display from the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-column-does-not-display-from-the-macro/m-p/479918#M123947</link>
      <description>&lt;P&gt;I have a large data set, and I need to create 2x2 tables to do some further calculation.&lt;/P&gt;&lt;P&gt;Part of he dataset looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;data X_data&lt;/U&gt;&lt;/P&gt;&lt;P&gt;X_target1_result&amp;nbsp; Y_target1_result&amp;nbsp;&amp;nbsp;result&lt;/P&gt;&lt;P&gt;Negative&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Positive&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Negative&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Positive&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Positive&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Negative&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;......&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where the&amp;nbsp;"result" column is empty, since I have multiply targets to compare, so I need to generate a Macro to do it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The macro code is:&lt;/P&gt;&lt;P&gt;*******************************************************************************&lt;/P&gt;&lt;P&gt;%MACRO compare(data, target, comp);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; data data1 (replace=yes);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;set &amp;amp;data;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%if "&amp;amp;comp._&amp;amp;target._result"="Positive" %then %do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if "Y_&amp;amp;target._result"="Positive" then "result"=TP;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else if "Y_&amp;amp;target._result"="Negative" then "result"=FN;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %else %if "&amp;amp;comp._&amp;amp;target._result"="Negative" %then %do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if "Y_&amp;amp;target._result"="Positive" then "result"=FP;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else if "Y_&amp;amp;target._result"="Negative" then "result"=TN;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*********more proc sql and other code **********&lt;/P&gt;&lt;P&gt;%MEND;&lt;/P&gt;&lt;P&gt;**********************************************************************************&lt;/P&gt;&lt;P&gt;So When I run this Macro in the main program:&lt;/P&gt;&lt;P&gt;%include "&amp;amp;macropath.compare.sas";&lt;/P&gt;&lt;P&gt;%compare(X_data, target1, X)&lt;/P&gt;&lt;P&gt;This ends up give me the column "result" in data1 still empty, not fill with TP, TN, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What mistake did I make and how to solve it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2018 15:37:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-column-does-not-display-from-the-macro/m-p/479918#M123947</guid>
      <dc:creator>y_fu</dc:creator>
      <dc:date>2018-07-20T15:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: Data column does not display from the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-column-does-not-display-from-the-macro/m-p/479923#M123949</link>
      <description>&lt;P&gt;Use the following option before you run your macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then run it again and show us the SASLOG. No, wait, you try to figure out what the error is from the SASLOG, and if you can't figure it out, then show us. Please click on the {i} icon and paste the RELEVANT parts of your SASLOG into the window that appears.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2018 15:49:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-column-does-not-display-from-the-macro/m-p/479923#M123949</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-20T15:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: Data column does not display from the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-column-does-not-display-from-the-macro/m-p/479927#M123950</link>
      <description>&lt;P&gt;Better would be to provide some example data and the calculations you need to do from those 2x2 tables. For example Proc Freq will do risks, risk differences, odds ratios and relative risks for 2x2 tables without much work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't want to use %if / %then/ %do inside a data step when manipulative values of data step variables. Also if you want to use a variables value in a data step&amp;nbsp;do &lt;STRONG&gt;not&lt;/STRONG&gt; place the macro code for the name&amp;nbsp;inside quotes.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if &amp;amp;comp._&amp;amp;target._result="Positive" then do;
   if Y_&amp;amp;target._result="Positive" then "result"=TP;
   else if Y_&amp;amp;target._result="Negative" then "result"=FN;
end;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second might be to consider coding text values lf "Positive" and "Negative" as 1 and 0. Use a custom format to assign desired display text as needed.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2018 15:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-column-does-not-display-from-the-macro/m-p/479927#M123950</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-20T15:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Data column does not display from the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-column-does-not-display-from-the-macro/m-p/479937#M123957</link>
      <description>&lt;P&gt;First this warning .... you should not be using macro language.&amp;nbsp; Not yet anyway.&amp;nbsp; You need to understand base SAS first or macro language will be useless.&amp;nbsp; Taking your program as an example, there is no SAS statement that looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"result" = FN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to refer to a variable named RESULT you would use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;result = FN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Same thing here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Y_&amp;amp;target._result" =&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;should be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Y_&amp;amp;target._result =&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In terms of getting the macro to work, you have done well to get rid of some of the percent signs.&amp;nbsp; Now get rid of the rest.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if&amp;nbsp; &amp;nbsp;(not %if)&lt;/P&gt;
&lt;P&gt;do&amp;nbsp; &amp;nbsp;(not %do)&lt;/P&gt;
&lt;P&gt;end&amp;nbsp; &amp;nbsp;(not %end)&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2018 16:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-column-does-not-display-from-the-macro/m-p/479937#M123957</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-20T16:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: Data column does not display from the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-column-does-not-display-from-the-macro/m-p/479964#M123980</link>
      <description>&lt;P&gt;Since the macro conditions can never be true, no code is created, and the step does essentially NOTHING except copying the dataset.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2018 17:14:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-column-does-not-display-from-the-macro/m-p/479964#M123980</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-20T17:14:29Z</dc:date>
    </item>
  </channel>
</rss>

