<?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 IF THEN Macro not creating Variable, no error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496753#M131460</link>
    <description>&lt;P&gt;Sorry you are right this absolutely does work I didn't notice the missing % for IF and THEN. It is not needed I guess?&lt;/P&gt;</description>
    <pubDate>Tue, 18 Sep 2018 21:16:21 GMT</pubDate>
    <dc:creator>Swann2000</dc:creator>
    <dc:date>2018-09-18T21:16:21Z</dc:date>
    <item>
      <title>SAS IF THEN Macro not creating Variable, no error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496723#M131439</link>
      <description>&lt;P&gt;Since there are no errors in the log, I'm not sure what's going wrong. In the macro, I'm trying to create the variable MAJOR_CAT based on DIAG1. See blow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET DATAPULL = DATATWO;&lt;BR /&gt;%LET OUTDATA = DATAONE;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE &amp;amp;DATAPULL. AS SELECT&lt;/P&gt;&lt;P&gt;/*PULL A BUNCH OF VARIABLES WORKS FINE*/&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO MAJOR_CAT;&lt;BR /&gt;%IF DIAG1 =: 'F0' %THEN &amp;amp;MAJOR_CAT. = 'Organic, including symptomatic, mental disorders';&lt;BR /&gt;%IF DIAG1 =: 'F1' %THEN &amp;amp;MAJOR_CAT. = 'Mental and behavioural disorders due to psychoative substance use';&lt;BR /&gt;%IF DIAG1 =: 'F2' %THEN &amp;amp;MAJOR_CAT. = 'Schizophrena, schizotypal and delusional disorders';&lt;BR /&gt;%IF DIAG1 =: 'F3' %THEN &amp;amp;MAJOR_CAT. = 'Mood [affective] disorders';&lt;BR /&gt;%IF DIAG1 =: 'F4' %THEN &amp;amp;MAJOR_CAT. = 'Neurotic, stress-related and somatoform disorders';&lt;BR /&gt;%IF DIAG1 =: 'F5' %THEN &amp;amp;MAJOR_CAT. = 'Behavioural syndromes associated with physiological disturbances and physical factors';&lt;BR /&gt;%IF DIAG1 =: 'F6' %THEN &amp;amp;MAJOR_CAT. = 'Disorders of adult personality and behaviour';&lt;BR /&gt;%IF DIAG1 =: 'F7' %THEN &amp;amp;MAJOR_CAT. = 'Mental retardation';&lt;BR /&gt;%IF DIAG1 =: 'F8' %THEN &amp;amp;MAJOR_CAT. = 'Disorders of psychological development';&lt;BR /&gt;%IF DIAG1 =: 'F90' OR DIAG1 =: 'F91' OR DIAG1 =: 'F92' OR DIAG1 =: 'F93' OR DIAG1 =: 'F94' OR DIAG1 =: 'F95' OR DIAG1 =: 'F96'&lt;BR /&gt;OR DIAG1 =: 'F97' OR DIAG1 =: 'F98' %THEN &amp;amp;MAJOR_CAT. = 'Behavoural and emotional disorders with onset usually occurring in childhood and adolescence';&lt;BR /&gt;%IF DIAG1 =: 'F99' %THEN &amp;amp;MAJOR_CAT. = 'Unspecified mental disorder';&lt;BR /&gt;%MEND MAJOR_CAT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*HERE I CALL THE MACRO AND GET MY &amp;amp;DATAPULL SET SPIT OUT WITH NO MAJOR_CAT VARIABLE*/&lt;/P&gt;&lt;P&gt;DATA &amp;amp;OUTDATA.;&lt;BR /&gt;SET &amp;amp;DATAPULL.;&lt;BR /&gt;%MAJOR_CAT;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is a non-macro program version of the macro program that works correctly:&lt;/P&gt;&lt;P&gt;DATA &amp;amp;OUTDATA.;&lt;BR /&gt;SET &amp;amp;DATAPULL.;&lt;BR /&gt;IF DIAG1 =: 'F0' THEN MAJOR_CAT = 'Organic, including symptomatic, mental disorders';&lt;BR /&gt;IF DIAG1 =: 'F1' THEN MAJOR_CAT = 'Mental and behavioural disorders due to psychoative substance use';&lt;BR /&gt;IF DIAG1 =: 'F2' THEN MAJOR_CAT = 'Schizophrena, schizotypal and delusional disorders';&lt;BR /&gt;IF DIAG1 =: 'F3' THEN MAJOR_CAT = 'Mood [affective] disorders';&lt;BR /&gt;IF DIAG1 =: 'F4' THEN MAJOR_CAT = 'Neurotic, stress-related and somatoform disorders';&lt;BR /&gt;IF DIAG1 =: 'F5' THEN MAJOR_CAT = 'Behavioural syndromes associated with physiological disturbances and physical factors';&lt;BR /&gt;IF DIAG1 =: 'F6' THEN MAJOR_CAT = 'Disorders of adult personality and behaviour';&lt;BR /&gt;IF DIAG1 =: 'F7' THEN MAJOR_CAT = 'Mental retardation';&lt;BR /&gt;IF DIAG1 =: 'F8' THEN MAJOR_CAT = 'Disorders of psychological development';&lt;BR /&gt;IF DIAG1 =: 'F90' OR DIAG1 =: 'F91' OR DIAG1 =: 'F92' OR DIAG1 =: 'F93' OR DIAG1 =: 'F94' OR DIAG1 =: 'F95' OR DIAG1 =: 'F96' OR DIAG1 =: 'F97' OR DIAG1 =: 'F98' THEN MAJOR_CAT = 'Behavoural and emotional disorders with onset usually occurring in childhood and adolescence';&lt;BR /&gt;IF DIAG1 =: 'F99' THEN MAJOR_CAT = 'Unspecified mental disorder';&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 20:30:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496723#M131439</guid>
      <dc:creator>Swann2000</dc:creator>
      <dc:date>2018-09-18T20:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS IF THEN Macro not creating Variable, no error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496733#M131444</link>
      <description>&lt;P&gt;Yes, but your code is IF/THEN but references a &lt;STRONG&gt;data step variable&lt;/STRONG&gt; in a &lt;STRONG&gt;PROC SQL&lt;/STRONG&gt; step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're currently mixing macro, data step and sql code in a manner that doesn't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest using the data step or changing the code to be CASE statements which would work in SQL. Not really sure where the macro variable major cat is created either.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 20:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496733#M131444</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-18T20:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS IF THEN Macro not creating Variable, no error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496742#M131450</link>
      <description>&lt;P&gt;Assuming you could create a macro here, how would it be useful?&amp;nbsp; You already have a working program.&amp;nbsp; You might need to explain a little more.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your time would be better spent upgrading the working program.&amp;nbsp; Add the word ELSE as appropriate so it will run faster.&amp;nbsp; Set a length for MAJOR_CAT so&amp;nbsp; its values won't get truncated.&amp;nbsp; Once you have improved the non-macro code, then consider whether there would be value in converting it to a macro.&amp;nbsp; But the example you have posted does not illustrate any benefits of using a macro.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 20:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496742#M131450</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-18T20:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAS IF THEN Macro not creating Variable, no error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496743#M131451</link>
      <description>&lt;P&gt;there is value in converting it to a macro because I am going to use it four times or more throughout my program.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 20:58:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496743#M131451</guid>
      <dc:creator>Swann2000</dc:creator>
      <dc:date>2018-09-18T20:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS IF THEN Macro not creating Variable, no error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496745#M131453</link>
      <description>&lt;P&gt;Definitely a valid and valuable use.&amp;nbsp; It's simpler than you are thinking:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro mylogic;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;IF DIAG1 =: 'F0' THEN MAJOR_CAT = 'Organic, including symptomatic, mental disorders';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IF DIAG1 =: 'F1' THEN MAJOR_CAT = 'Mental and behavioural disorders due to psychoative substance use';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IF DIAG1 =: 'F2' THEN MAJOR_CAT = 'Schizophrena, schizotypal and delusional disorders';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IF DIAG1 =: 'F3' THEN MAJOR_CAT = 'Mood [affective] disorders';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IF DIAG1 =: 'F4' THEN MAJOR_CAT = 'Neurotic, stress-related and somatoform disorders';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IF DIAG1 =: 'F5' THEN MAJOR_CAT = 'Behavioural syndromes associated with physiological disturbances and physical factors';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IF DIAG1 =: 'F6' THEN MAJOR_CAT = 'Disorders of adult personality and behaviour';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IF DIAG1 =: 'F7' THEN MAJOR_CAT = 'Mental retardation';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IF DIAG1 =: 'F8' THEN MAJOR_CAT = 'Disorders of psychological development';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IF DIAG1 =: 'F90' OR DIAG1 =: 'F91' OR DIAG1 =: 'F92' OR DIAG1 =: 'F93' OR DIAG1 =: 'F94' OR DIAG1 =: 'F95' OR DIAG1 =: 'F96' OR DIAG1 =: 'F97' OR DIAG1 =: 'F98' THEN MAJOR_CAT = 'Behavoural and emotional disorders with onset usually occurring in childhood and adolescence';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IF DIAG1 =: 'F99' THEN MAJOR_CAT = 'Unspecified mental disorder';&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%mend mylogic;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Note that I haven't implemented any of the suggested changes to the code.&amp;nbsp; You can use this statement in four places as needed:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%mylogic&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 21:01:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496745#M131453</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-18T21:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAS IF THEN Macro not creating Variable, no error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496749#M131456</link>
      <description>&lt;P&gt;I get the same results using MAJOR_CAT as I do &amp;amp;MAJOR_CAT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you recommending not invoke the macro within a datastep? If I just invoke the macro as %mylogic&amp;nbsp;it resolves and writes some stuff to the log but does not produce output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 21:07:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496749#M131456</guid>
      <dc:creator>Swann2000</dc:creator>
      <dc:date>2018-09-18T21:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAS IF THEN Macro not creating Variable, no error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496752#M131459</link>
      <description>&lt;P&gt;You listed a program as "working".&amp;nbsp; If that program works, then this one will also work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;DATA &amp;amp;OUTDATA.;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SET &amp;amp;DATAPULL.;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%mylogic&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;It generates exactly the same statements in exactly the same order.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 21:12:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496752#M131459</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-18T21:12:16Z</dc:date>
    </item>
    <item>
      <title>Re: SAS IF THEN Macro not creating Variable, no error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496753#M131460</link>
      <description>&lt;P&gt;Sorry you are right this absolutely does work I didn't notice the missing % for IF and THEN. It is not needed I guess?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 21:16:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496753#M131460</guid>
      <dc:creator>Swann2000</dc:creator>
      <dc:date>2018-09-18T21:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAS IF THEN Macro not creating Variable, no error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496755#M131462</link>
      <description>&lt;P&gt;A format would actually be a lot cleaner IMO.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/234355"&gt;@Swann2000&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;there is value in converting it to a macro because I am going to use it four times or more throughout my program.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 21:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496755#M131462</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-18T21:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: SAS IF THEN Macro not creating Variable, no error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496757#M131464</link>
      <description>&lt;P&gt;That's correct.&amp;nbsp; Writing a macro does not require changing all your IF THEN statements to %IF %THEN.&amp;nbsp; It all depends on what the macro is intended to accomplish.&amp;nbsp; The general guidelines:&amp;nbsp; macros generate SAS code.&amp;nbsp; The generated SAS code (not the macro language) processes your data.&amp;nbsp; So the generated SAS code has to be accurate.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 21:36:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-IF-THEN-Macro-not-creating-Variable-no-error/m-p/496757#M131464</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-18T21:36:36Z</dc:date>
    </item>
  </channel>
</rss>

