<?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 How do I use a macro variable inside a IN statement in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89042#M25367</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to do the following:&lt;/P&gt;&lt;P&gt;1)&amp;nbsp; Read in a variable from the data set and&lt;/P&gt;&lt;P&gt;2)&amp;nbsp; Create a macro variable from it to be able to,&lt;/P&gt;&lt;P&gt;3)&amp;nbsp; Put in an IF statement that can be used on the left hand side of the IN part of the IF statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See the following program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was wondering if I can some how execute the second IF statement instead of the first one?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It works correctly with the first one, but originally I thought of the first one and tried to&lt;/P&gt;&lt;P&gt;make it work.&amp;nbsp; I never could figure it out.&amp;nbsp; What could I use instead of the SYMPUT?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Nancy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 03 Dec 2012 20:01:19 GMT</pubDate>
    <dc:creator>SASHunter</dc:creator>
    <dc:date>2012-12-03T20:01:19Z</dc:date>
    <item>
      <title>How do I use a macro variable inside a IN statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89042#M25367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to do the following:&lt;/P&gt;&lt;P&gt;1)&amp;nbsp; Read in a variable from the data set and&lt;/P&gt;&lt;P&gt;2)&amp;nbsp; Create a macro variable from it to be able to,&lt;/P&gt;&lt;P&gt;3)&amp;nbsp; Put in an IF statement that can be used on the left hand side of the IN part of the IF statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See the following program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was wondering if I can some how execute the second IF statement instead of the first one?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It works correctly with the first one, but originally I thought of the first one and tried to&lt;/P&gt;&lt;P&gt;make it work.&amp;nbsp; I never could figure it out.&amp;nbsp; What could I use instead of the SYMPUT?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Nancy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Dec 2012 20:01:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89042#M25367</guid>
      <dc:creator>SASHunter</dc:creator>
      <dc:date>2012-12-03T20:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use a macro variable inside a IN statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89043#M25368</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not familiar with the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in (&amp;amp;z:2012) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What are you expecting that to do? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you explain a bit more what you're trying to do, are you sure you need macro variables?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Dec 2012 20:40:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89043#M25368</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2012-12-03T20:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use a macro variable inside a IN statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89044#M25369</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Generally you can't use a macro variable in the datastep that creates it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the problem with using the following if it gets the output you need?&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN lang="EN"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;if PUSF2 &amp;gt;= newage AND PUSF2 &amp;lt; 2012 then&amp;nbsp; /* other than it should be &amp;lt;= if you want to consider it equal to the attempted IN statement*/&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN lang="EN"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if newage &amp;lt;= PUSF2 &amp;lt;= 2012&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And I also have wanted more than once for IN to accept variables instead of only literal values.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Dec 2012 20:58:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89044#M25369</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2012-12-03T20:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use a macro variable inside a IN statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89045#M25370</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I am trying to do is process each record and read the birth year of the mother (pebirthy).&amp;nbsp; Than add twelve to it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I want to use this 'newage' year and put it into a macro variable, which will be updated for each record.&amp;nbsp; Than I will test to see if the year they said they had their first child (pusf2) falls in between the new macro variable and 2012.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So the line that I have commented out -&amp;nbsp; '&amp;nbsp; If pusf2 IN ( &amp;amp;z : 2012 ) then&amp;nbsp; '&lt;/P&gt;&lt;P&gt;was the first thing I thought about because of the shorten code, but of course it doesn't work. Unless someone can show me that it does. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And thanks ballardw - your right, I need the &amp;lt;=&amp;nbsp; sign before the 2012.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your input. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Dec 2012 13:29:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89045#M25370</guid>
      <dc:creator>SASHunter</dc:creator>
      <dc:date>2012-12-04T13:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use a macro variable inside a IN statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89046#M25371</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;this seems like a case option in proc sql.&lt;/P&gt;&lt;P&gt;or using your new column in a datastep...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table temp2 as select *, pebirthy+12 as newage, case when (pebirthy+12) le 2012 then 'yes' else 'nooo' end from temp;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm just missing the last calculation but it's close&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Dec 2012 14:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89046#M25371</guid>
      <dc:creator>mojerry2</dc:creator>
      <dc:date>2012-12-04T14:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use a macro variable inside a IN statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89047#M25372</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure why you want the macro variable?&amp;nbsp; Usually you would use macro variables to dynamically generate text that you could not code directly. But your example just looks like you want to calculate a variable and then compare its value to another existing variable. No need to dynamically generate code. Looks like you want something like this. (Note I renamed newage to newyear as it seemed a better indication of the content of the variable.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data temp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; input name $&amp;nbsp; pebirthy pusf2 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; newyear= pebirthy + 12;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if newyear &amp;lt;= PUSF2 &amp;lt; 2012 then flag = 'Y';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; else flag = 'N';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; put (name pebirthy pusf2 newyear flag) (=);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;cards;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Tina&amp;nbsp; 1985 -1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Betty&amp;nbsp; 1975 1990&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Sue 1951 1961&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Sally 1988 2011&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Marylu 1964 2001&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Janet 1978 1997&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Jean 1995 2006&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;name=Tina pebirthy=1985 pusf2=-1 newyear=1997 flag=N&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;name=Betty pebirthy=1975 pusf2=1990 newyear=1987 flag=Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;name=Sue pebirthy=1951 pusf2=1961 newyear=1963 flag=N&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;name=Sally pebirthy=1988 pusf2=2011 newyear=2000 flag=Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;name=Marylu pebirthy=1964 pusf2=2001 newyear=1976 flag=Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;name=Janet pebirthy=1978 pusf2=1997 newyear=1990 flag=Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;name=Jean pebirthy=1995 pusf2=2006 newyear=2007 flag=N&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now if you do not need to store the value of birth year + 12 then you can just include the addition in the conditional used in the IF statement and eliminate the creation of a new variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if pebirthy + 12 &lt;/SPAN&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;lt;= PUSF2 &amp;lt; 2012 then flag = 'Y';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; else flag = 'N';&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Dec 2012 14:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89047#M25372</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-12-04T14:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use a macro variable inside a IN statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89048#M25373</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tom,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your input.&amp;nbsp; I like your bottom example, because 'No' I don't really want an extra variable.&amp;nbsp; So I'll recode it as you put it in the bottom of your post.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Dec 2012 14:56:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89048#M25373</guid>
      <dc:creator>SASHunter</dc:creator>
      <dc:date>2012-12-04T14:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use a macro variable inside a IN statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89049#M25374</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tom (or anyone)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I mark my questions with 'answered'&amp;nbsp; - where it says 'This question is:'&amp;nbsp; ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 12:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89049#M25374</guid>
      <dc:creator>SASHunter</dc:creator>
      <dc:date>2012-12-06T12:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use a macro variable inside a IN statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89050#M25375</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN lang="EN"&gt;Though this thread is answered, I once was in trouble until I found this paper&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN lang="EN"&gt;&lt;A href="http://www.nesug.org/Proceedings/nesug09/cc/cc05.pdf"&gt;http://www.nesug.org/Proceedings/nesug09/cc/cc05.pdf&lt;/A&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN lang="EN"&gt;and used it as below- &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN lang="EN"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN lang="EN"&gt;options minoperator;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;%if %eval(&amp;amp;D in 07,14,21,28,35,42,49,56,63,70,77,84,91) %then %do;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN lang="EN"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 14:52:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-use-a-macro-variable-inside-a-IN-statement/m-p/89050#M25375</guid>
      <dc:creator>krithi</dc:creator>
      <dc:date>2012-12-06T14:52:35Z</dc:date>
    </item>
  </channel>
</rss>

