<?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: Getting a list of variables to resolve correctly in a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Getting-a-list-of-variables-to-resolve-correctly-in-a-macro/m-p/275063#M54958</link>
    <description>&lt;P&gt;IN doesn't work quite that way. It want's explicit values. If you were doing a comparison with another variable created that held the name of the diagnoses then the names would have to be quoted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If all of your codes are binary you could test to see if the MAXIMUM of any of the values is 1 for a similar comparison&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so&lt;/P&gt;
&lt;P&gt;If Max( ACIDBASE, COMAMETU, DIABETIC) = 1 then metamisc = 1;&lt;/P&gt;
&lt;P&gt;would be equivalent. Which requires a comma delimited list. So this may work for you:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro aggdx(dxlist, rolled_up_dx);
   %let Dxlist= %sysfunc(translate(&amp;amp;dxlist,%str(,),%str( )));

  if max(&amp;amp;dxlist)=1 then &amp;amp;rolled_up_dx = 1;

%mend;&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;You were&amp;nbsp;also confusing MACRO comparisons %if /%then with the desired Datastep code if then.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Jun 2016 18:21:46 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-06-03T18:21:46Z</dc:date>
    <item>
      <title>Getting a list of variables to resolve correctly in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-a-list-of-variables-to-resolve-correctly-in-a-macro/m-p/275047#M54951</link>
      <description>&lt;P&gt;I have 100,000 patients, each of which receives one of 116 diagnoses. I'm exploding the 116 diagnoses into 116 binary variables. Some of these diagnoses are rare, so I want to roll them up into an diagnosis that is much more prevalent, and pare down the list of 116 to around 30 common diagnoses. I'm using the code below to try to do that, but the %if condition always returns a FALSE. That should not be the case for patients with rare diagnoses. Do you know what is wrong with my code?&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;Andrew&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options minoperator;&lt;/P&gt;&lt;P&gt;%macro aggdx(dxlist, rolled_up_dx);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;%if diagnosis in &amp;amp;dxlist %then &amp;amp;rolled_up_dx = 1;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data hosp1; set hosp2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;/* Example of what I want to do:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if acidbase = 1 or comametu = 1 or diabetic = 1 then metamisc = 1;&lt;/P&gt;&lt;P&gt;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;%aggdx(ACIDBASE COMAMETU DIABETIC, METAMISC)&lt;/P&gt;&lt;P&gt;/* So I'll have about 30 calls to %aggdx, one for each of the common diagnoses */ ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2016 17:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-a-list-of-variables-to-resolve-correctly-in-a-macro/m-p/275047#M54951</guid>
      <dc:creator>DocMartin</dc:creator>
      <dc:date>2016-06-03T17:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a list of variables to resolve correctly in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-a-list-of-variables-to-resolve-correctly-in-a-macro/m-p/275059#M54956</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83350"&gt;@DocMartin﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are confusing data step and macro logic: &lt;FONT face="courier new,courier"&gt;%if diagnosis in &amp;amp;dxlist&lt;/FONT&gt; ... checks whether the string &lt;STRONG&gt;diagnosis&lt;/STRONG&gt;&amp;nbsp;(&lt;EM&gt;not&lt;/EM&gt; the value of a data step variable of this name!) is contained in the value of the first macro parameter (ACIDBASE ... in your example).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, if&amp;nbsp;&lt;STRONG&gt;diagnosis&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;is a character variable in dataset HOSP2, containing diagnoses like "ACIDBASE" etc., the following macro definition should work:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro aggdx(dxlist, rolled_up_dx);
  if diagnosis in ("%sysfunc(tranwrd(&amp;amp;dxlist,%str( )," "))") then &amp;amp;rolled_up_dx = 1;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, IF/THEN as well as IN are data step code generated by the macro. In particular, the option MINOPERATOR is not necessary for this to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to use your binary variables instead of the character variable DIAGNOSIS, the macro code will be different, of course.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2016 18:17:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-a-list-of-variables-to-resolve-correctly-in-a-macro/m-p/275059#M54956</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-06-03T18:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a list of variables to resolve correctly in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-a-list-of-variables-to-resolve-correctly-in-a-macro/m-p/275063#M54958</link>
      <description>&lt;P&gt;IN doesn't work quite that way. It want's explicit values. If you were doing a comparison with another variable created that held the name of the diagnoses then the names would have to be quoted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If all of your codes are binary you could test to see if the MAXIMUM of any of the values is 1 for a similar comparison&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so&lt;/P&gt;
&lt;P&gt;If Max( ACIDBASE, COMAMETU, DIABETIC) = 1 then metamisc = 1;&lt;/P&gt;
&lt;P&gt;would be equivalent. Which requires a comma delimited list. So this may work for you:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro aggdx(dxlist, rolled_up_dx);
   %let Dxlist= %sysfunc(translate(&amp;amp;dxlist,%str(,),%str( )));

  if max(&amp;amp;dxlist)=1 then &amp;amp;rolled_up_dx = 1;

%mend;&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;You were&amp;nbsp;also confusing MACRO comparisons %if /%then with the desired Datastep code if then.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2016 18:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-a-list-of-variables-to-resolve-correctly-in-a-macro/m-p/275063#M54958</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-06-03T18:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a list of variables to resolve correctly in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-a-list-of-variables-to-resolve-correctly-in-a-macro/m-p/275069#M54960</link>
      <description>&lt;PRE&gt;"Do you know what is wrong with my code?"
&lt;/PRE&gt;
&lt;P&gt;Yes, you are using macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You simply need to build a dataset with Diagnosis - Common Diagnosis equivalences and use it to recode your observations. The last part can be done with a datastep MERGE operation, a format recode, or a SQL join.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Keep macros for cases where everything else fails.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2016 18:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-a-list-of-variables-to-resolve-correctly-in-a-macro/m-p/275069#M54960</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-03T18:30:26Z</dc:date>
    </item>
  </channel>
</rss>

