<?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: If Then Else in Marco in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871586#M344324</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/220658"&gt;@altadata1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for the respond.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't understand this "&lt;SPAN&gt;But none of your macro calls use anything like nocR3 as the value of VAR1". Could you explain it a little bit more?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I can use regular IF The DO, but I have 33 different values for each macro variables of var 1 to var 4. it means 33 different values for var1, 33 values for var2....&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any tips to make it easier or less prone to error?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;BTW, I did test the regular&amp;nbsp;if then do and it works.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Many thanks again, &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What do the values of the macro parameters VAR1 to VAR4 represent?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are they supposed to be the NAMES of the variables you want to check with the generated SAS code?&amp;nbsp; If so you would use the macro variable like this to generate an IF statement where the NAME of the variable being tested changes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   if &amp;amp;var1 = 'YES' then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Are they supposed to be the VALUES of variables you want to check?&amp;nbsp; If so then you can use it like this to test whether a SPECIFIC variable has that value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    if CONDITION_CODE = &amp;amp;var1 then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In this example if CONDITION_CODE is a numeric variable then values you would pass to VAR1 would be strings that look like numbers, such as 12 or 2.5.&amp;nbsp; But if CONDITION_CODE is a character variable then the strings you pass in var1 will need to be quoted strings, such as 'YES' or "NO".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Apr 2023 13:48:09 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-04-24T13:48:09Z</dc:date>
    <item>
      <title>If Then Else in Marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871246#M344138</link>
      <description>&lt;P&gt;I created this macro. But, there is no "Qunt" in the data set "wage".&amp;nbsp;&lt;/P&gt;&lt;P&gt;I received SAS warning that: The variable Qunt in the DROP, or RENAME list has never been referenced.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any tips would be much appreciated.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro quantile(var1=, var2=, var3=, var4=);

DATA wage; SET AVG_wage;

 

                        %IF compyr = '2007-08' and sex = '1' %THEN %DO;

                             %IF   nocR3 = &amp;amp;var1 %then %do;

                                   if realwages &amp;lt;&amp;amp;var2 then Qunt= 1; else if &amp;amp;var2 &amp;lt;realwages &amp;lt;&amp;amp;var3 then Qunt= 2; else if realwages &amp;gt;&amp;amp;var3 then Qunt= 3; else  Qunt= .; %end;

                                                      %else %IF md_nocR3 = &amp;amp;var4 %then %do;

                                  if realwages &amp;lt;&amp;amp;var2 then Qunt= 1; else if &amp;amp;var2 &amp;lt;realwages &amp;lt;&amp;amp;var3 then Qunt= 2; else if realwages &amp;gt;&amp;amp;var3 then Qunt= 3; else  Qunt= .; %end;

 


                        %END;

                        keep sex compyr nocR3 Qunt;

                  RUN;

 

%mend quantile;

            options symbolgen;

            %quantile(var1='00', var2=47.5 , var3 =95.9);

            %quantile(var4='11', var2=22.2, var3 =51.5;

            %quantile(var4='12', var2=25.1 , var3 =42.8);

            %quantile(var4='13', var2=23.2 , var3 =32.0);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Apr 2023 19:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871246#M344138</guid>
      <dc:creator>altadata1</dc:creator>
      <dc:date>2023-04-21T19:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: If Then Else in Marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871249#M344141</link>
      <description>&lt;P&gt;You do not use MACRO %if/%then with DATA set variables. Use regular if/then/else with the data set variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro processor basically does not see data set variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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/220658"&gt;@altadata1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I created this macro. But, there is no "Qunt" in the data set "wage".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I received SAS warning that: The variable Qunt in the DROP, or RENAME list has never been referenced.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any tips would be much appreciated.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;%macro quantile(var1=, var2=, var3=, var4=);

DATA wage; SET AVG_wage;

 

                        %IF compyr = '2007-08' and sex = '1' %THEN %DO;

                             %IF   nocR3 = &amp;amp;var1 %then %do;

                                   if realwages &amp;lt;&amp;amp;var2 then Qunt= 1; else if &amp;amp;var2 &amp;lt;realwages &amp;lt;&amp;amp;var3 then Qunt= 2; else if realwages &amp;gt;&amp;amp;var3 then Qunt= 3; else  Qunt= .; %end;

                                                      %else %IF md_nocR3 = &amp;amp;var4 %then %do;

                                  if realwages &amp;lt;&amp;amp;var2 then Qunt= 1; else if &amp;amp;var2 &amp;lt;realwages &amp;lt;&amp;amp;var3 then Qunt= 2; else if realwages &amp;gt;&amp;amp;var3 then Qunt= 3; else  Qunt= .; %end;

 


                        %END;

                        keep sex compyr nocR3 Qunt;

                  RUN;

 

%mend quantile;

            options symbolgen;

            %quantile(var1='00', var2=47.5 , var3 =95.9);

            %quantile(var4='11', var2=22.2, var3 =51.5;

            %quantile(var4='12', var2=25.1 , var3 =42.8);

            %quantile(var4='13', var2=23.2 , var3 =32.0);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 19:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871249#M344141</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-04-21T19:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: If Then Else in Marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871281#M344152</link>
      <description>&lt;P&gt;Your %IF conditions can never be true.&amp;nbsp; Look at the first one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%IF compyr = '2007-08' and sex = '1' %THEN %DO;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SAS will compare strings byte by byte until there is a difference.&amp;nbsp; A lowercase letter C will never equal a single quote character so the first test is FALSE.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second %IF (which will never execute because the first is never going to be true)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  %IF   nocR3 = &amp;amp;var1 %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;might possibly be true since here you are comparing the string nocR3 to the value of the macro variable VAR1.&amp;nbsp; But none of your macro calls use anything like nocR3 as the value of VAR1.&amp;nbsp; Three of them do not set any value for the VAR1 parameter.&amp;nbsp; And the fourth has another quoted string which will never match nocR3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to test the value of dataset variables named COMPYR or SEX or NOCR3 then you need use actual SAS code instead of macro code.&amp;nbsp; So you probably want regular IF statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Apr 2023 02:13:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871281#M344152</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-22T02:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: If Then Else in Marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871286#M344154</link>
      <description>&lt;P&gt;&lt;STRONG&gt;BEFORE&lt;/STRONG&gt; you engage in macro programming, you MUST have working code&amp;nbsp;&lt;EM&gt;without any macro elements&lt;/EM&gt; which solves a single, non-dynamic instance of your issue.&lt;/P&gt;
&lt;P&gt;Then, you identify the parts which need to be dynamic, and replace&amp;nbsp;&lt;EM&gt;only those&lt;/EM&gt; with macro variables or create them through macro statements.&lt;/P&gt;
&lt;P&gt;So please show us the initial SAS code.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Apr 2023 06:28:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871286#M344154</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-04-22T06:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: If Then Else in Marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871566#M344314</link>
      <description>&lt;P&gt;Thank you for the respond.&lt;/P&gt;&lt;P&gt;The problem is that I have 33 different values for each variables of var1 to var 4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mandana&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 12:55:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871566#M344314</guid>
      <dc:creator>altadata1</dc:creator>
      <dc:date>2023-04-24T12:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: If Then Else in Marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871568#M344315</link>
      <description>&lt;P&gt;Thank you for the respond.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't understand this "&lt;SPAN&gt;But none of your macro calls use anything like nocR3 as the value of VAR1". Could you explain it a little bit more?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I can use regular IF The DO, but I have 33 different values for each macro variables of var 1 to var 4. it means 33 different values for var1, 33 values for var2....&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any tips to make it easier or less prone to error?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;BTW, I did test the regular&amp;nbsp;if then do and it works.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Many thanks again, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 12:59:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871568#M344315</guid>
      <dc:creator>altadata1</dc:creator>
      <dc:date>2023-04-24T12:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: If Then Else in Marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871570#M344317</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/220658"&gt;@altadata1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for the respond.&lt;/P&gt;
&lt;P&gt;The problem is that I have 33 different values for each variables of var1 to var 4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Mandana&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is not the problem with your code. That is a different problem. First, as stated above, you have to create &lt;FONT color="#FF0000"&gt;working&lt;/FONT&gt; SAS code without macros and without macro variables for (let's say) two of the different values. You have to get that to work, because if you can't get that to work without macros and without macro variables, then it will NEVER work with macros or with macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, please show us that &lt;FONT color="#FF0000"&gt;working&lt;/FONT&gt; SAS code without macros and without macro variables for (let's say) two of the different values. Once you show us that, we can help you write code that works for 33 different values and four variables.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 13:04:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871570#M344317</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-24T13:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: If Then Else in Marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871586#M344324</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/220658"&gt;@altadata1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for the respond.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't understand this "&lt;SPAN&gt;But none of your macro calls use anything like nocR3 as the value of VAR1". Could you explain it a little bit more?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I can use regular IF The DO, but I have 33 different values for each macro variables of var 1 to var 4. it means 33 different values for var1, 33 values for var2....&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any tips to make it easier or less prone to error?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;BTW, I did test the regular&amp;nbsp;if then do and it works.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Many thanks again, &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What do the values of the macro parameters VAR1 to VAR4 represent?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are they supposed to be the NAMES of the variables you want to check with the generated SAS code?&amp;nbsp; If so you would use the macro variable like this to generate an IF statement where the NAME of the variable being tested changes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   if &amp;amp;var1 = 'YES' then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Are they supposed to be the VALUES of variables you want to check?&amp;nbsp; If so then you can use it like this to test whether a SPECIFIC variable has that value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    if CONDITION_CODE = &amp;amp;var1 then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In this example if CONDITION_CODE is a numeric variable then values you would pass to VAR1 would be strings that look like numbers, such as 12 or 2.5.&amp;nbsp; But if CONDITION_CODE is a character variable then the strings you pass in var1 will need to be quoted strings, such as 'YES' or "NO".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 13:48:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871586#M344324</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-24T13:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: If Then Else in Marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871629#M344356</link>
      <description>&lt;P&gt;Thank you for your respond. Here is the non-macro syntax for the test and it works well.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;ATA wage; SET AVG_wage;

             IF md_compyr = '2007-08' and sex = '1' THEN DO;
                            IF    md_nocR3 = '00' then do;
                                  if realwages &amp;lt;47.5 then Qunt= 1; else if 47.5 &amp;lt;realwages &amp;lt;95.9 then Qunt= 2; else if realwages &amp;gt;95.9 then Qunt= 3; else  Qunt= .; End;

                           ELSE IF md_nocR3 = '11' then do;
                                  if realwages &amp;lt;22.2 then Qunt= 1; else if 22.2 &amp;lt;realwages &amp;lt;51.5 then Qunt= 2; else if realwages &amp;gt;51.5 then Qunt= 3; else  Qunt= .;  End;

                END;

                        keep sex md_compyr md_nocR3 Qunt ;

                  RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Apr 2023 15:19:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871629#M344356</guid>
      <dc:creator>altadata1</dc:creator>
      <dc:date>2023-04-24T15:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: If Then Else in Marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871630#M344357</link>
      <description>&lt;P&gt;This is the working code:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;DATA wage; SET AVG_wage;

             IF md_compyr = '2007-08' and sex = '1' THEN DO;
                            IF    md_nocR3 = '00' then do;
                                  if realwages &amp;lt;47.5 then Qunt= 1; else if 47.5 &amp;lt;realwages &amp;lt;95.9 then Qunt= 2; else if realwages &amp;gt;95.9 then Qunt= 3; else  Qunt= .; End;

                           ELSE IF md_nocR3 = '11' then do;
                                  if realwages &amp;lt;22.2 then Qunt= 1; else if 22.2 &amp;lt;realwages &amp;lt;51.5 then Qunt= 2; else if realwages &amp;gt;51.5 then Qunt= 3; else  Qunt= .;  End;

                END;

                        keep sex md_compyr md_nocR3 Qunt ;

                  RUN;&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Apr 2023 15:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871630#M344357</guid>
      <dc:creator>altadata1</dc:creator>
      <dc:date>2023-04-24T15:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: If Then Else in Marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871654#M344374</link>
      <description>&lt;P&gt;Random indentation of the code is probably worse then no indentation.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wage;
  set AVG_wage;
  if md_compyr = '2007-08' and sex = '1' then do;
    if md_nocR3 = '00' then do;
      if realwages &amp;lt;47.5 then Qunt= 1;
      else if 47.5 &amp;lt;realwages &amp;lt;95.9 then Qunt= 2;
      else if realwages &amp;gt;95.9 then Qunt= 3; 
      else Qunt= .; 
    end;
    else if md_nocR3 = '11' then do;
      if realwages &amp;lt;22.2 then Qunt= 1; 
      else if 22.2 &amp;lt;realwages &amp;lt;51.5 then Qunt= 2; 
      else if realwages &amp;gt;51.5 then Qunt= 3; 
      else Qunt= .;  
    end;
  end;
  keep sex md_compyr md_nocR3 Qunt ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So it looks like you are converting REALWAGES into QUNT based on a set of cutoff values that depend on the values of SEX MD_COMPYR and MD_NOCR3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would recommend setting the cutoff values into a dataset and them merging by those three variables.&amp;nbsp; Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cutoffs;
  input md_compyr $ sex $ md_nocR3 $ cutoff1 cutoff2 ;
cards;
2007-08 1 00 47.5 95.9
2007-08 1 11 22.2 51.5 
;

data avg_wage;
  input md_compyr $ sex $ md_nocR3 $ realwages;
cards;
2007-08 1 00 45
2007-08 1 00 47.5
2007-08 1 00 50
2007-08 1 00 95.9
2007-08 1 00 98
2007-08 1 11 20
2007-08 1 11 22.2
2007-08 1 11 30
2007-08 1 11 51.5 
2007-08 1 11 60
;
 
data wage ;
  merge avg_wage cutoffs;
  by md_compyr sex md_nocr3 ;
  if missing(realwages) then Qunt=.;
  else if realwages &amp;lt; cutoff1 then Qunt=1;
  else if realwages &amp;lt; cutoff2 then Qunt=2;
  else Qunt=3;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note: Your original code is not assigning QUNT a value when it happens to fall exactly on either of the cut off values.&amp;nbsp; You might want to adjust one or more of the &amp;lt; operators to &amp;lt;= operators instead depending on which bin you want the values that fall exactly at the cuttoff to land in.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 16:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871654#M344374</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-24T16:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: If Then Else in Marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871672#M344382</link>
      <description>&lt;P&gt;Thank you sooooooo much. It works perfect.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 17:14:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Then-Else-in-Marco/m-p/871672#M344382</guid>
      <dc:creator>altadata1</dc:creator>
      <dc:date>2023-04-24T17:14:24Z</dc:date>
    </item>
  </channel>
</rss>

