<?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: Can a macro variable be a list of constants? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138888#M28031</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi chuakp;&lt;/P&gt;&lt;P&gt;I've attached some untested code based on my memory of something I desgned years ago.&amp;nbsp; The code is rudimentary and has many opportunities for typo errors on my part and improvement and enhancement on your part.&amp;nbsp; I would make this concept code work before you tried to finesse it out.&amp;nbsp; This concept code should allow you room to expand it if you need more than 20 output datasets or if you need to read more than 41 diagnosis fields.&amp;nbsp; I see a good opportunity to convert the code to a macro should the code work. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 01 May 2014 12:54:12 GMT</pubDate>
    <dc:creator>jwillis</dc:creator>
    <dc:date>2014-05-01T12:54:12Z</dc:date>
    <item>
      <title>Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138860#M28003</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a patient dataset where variables dx_code1-dx_code41 represent 41 diagnosis code variables.&amp;nbsp; My objective is to output only observations in which at least one of the 41 diagnosis codes matches a particular code.&amp;nbsp; I have 20 codes in mind, and I am trying to find an efficient way to program this in SAS.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to set up a macro variable that is a list of constants, but the following code does not work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let codes = '78060', '7784', '4659', '07999', '46611', '77989', '5990', '53081', '27651', '77189', '44619', '77982', '77931', '7746', 'V290', '77182', '7755', 'V070', '6910', '78791'; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data patients;&lt;/P&gt;&lt;P&gt;array a_dx dx_code1-dx_code41;&lt;/P&gt;&lt;P&gt;do j = 1 to 20;&lt;/P&gt;&lt;P&gt;&amp;nbsp; flag = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i = 1 to dim(a_dx);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if a_dx(i) in: codes(j) then flag = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if flag &amp;gt; 0 then output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop i flag;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions?&amp;nbsp; Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Apr 2014 19:17:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138860#M28003</guid>
      <dc:creator>chuakp</dc:creator>
      <dc:date>2014-04-29T19:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138861#M28004</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you're looking for a line like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if a_dx&lt;I&gt; in (&amp;amp;codes) then flag= 1.&lt;/I&gt;&lt;/P&gt;&lt;P&gt;or flag = (a_dx&lt;I&gt; in (&amp;amp;codes);&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However the values you have in the macrovariable codes are not all numeric so the dx_code variables better be character AND have the cases match, ie V070 not v070.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Apr 2014 19:27:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138861#M28004</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-04-29T19:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138862#M28005</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I solved the problem using a proc format style. I found it was easier to update and change the formats than the macros.&amp;nbsp; Also the format style provided me with the "OTHER" option.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Apr 2014 19:33:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138862#M28005</guid>
      <dc:creator>jwillis</dc:creator>
      <dc:date>2014-04-29T19:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138863#M28006</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the replies.&amp;nbsp; I apologize, but I just realized that my initial question was not clear.&amp;nbsp; Ideally, my code would produce twenty datasets.&amp;nbsp; The first dataset would be any patients where one of the 41 diagnosis codes was '78060', the second dataset would be any patients where one of the 41 diagnosis codes was '7784', etc.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How would I do this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Apr 2014 19:38:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138863#M28006</guid>
      <dc:creator>chuakp</dc:creator>
      <dc:date>2014-04-29T19:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138864#M28007</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc format is generally considered the better approach from the last time I posted a question on here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, be careful with the in: as the matches may not be exactly what you want.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Apr 2014 19:38:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138864#M28007</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-04-29T19:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138865#M28008</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How would I use PROC FORMAT to solve this problem?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Apr 2014 19:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138865#M28008</guid>
      <dc:creator>chuakp</dc:creator>
      <dc:date>2014-04-29T19:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138866#M28009</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi chuakp,&lt;/P&gt;&lt;P&gt;Below is one style of coding.&amp;nbsp; Coding the various possible values of diagnosis codes saves the need for using the upper, lower or proper case functions. If you have to add codes or change the output locations of codes, it is easier to manipulate the proc format than the data step code. The notfound and error statements are redundant.&amp;nbsp; I added them just to show you what is possible.&amp;nbsp; If a new&amp;nbsp; 'type' is ever added to SASHELP.CARS, the notfound dataset would contain any rows with the new type.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc format;&lt;BR /&gt;&amp;nbsp; value $diagx&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'SEDAN','Sedan','sedan'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'SUV','Suv','suv'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'SPORTS','Sports','sports'&amp;nbsp;&amp;nbsp;&amp;nbsp; = 3&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'WAGON','Wagon','wagon'&amp;nbsp;&amp;nbsp;&amp;nbsp; = 4&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'TRUCK','Truck','truck'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 5&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'HYBRID','Hybrid','hybrid'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 6&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OTHER&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 7&lt;BR /&gt;&amp;nbsp; run;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want1 want2 want3 want4 want5 want6 notfound error;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.cars;&lt;/P&gt;&lt;P&gt; if put(type,$diagx.) = 1 then output want1;&lt;/P&gt;&lt;P&gt; else if put(type,$diagx.) = 2 then output want2;&lt;/P&gt;&lt;P&gt; else if put(type,$diagx.) = 3 then output want3;&lt;/P&gt;&lt;P&gt; else if put(type,$diagx.) = 4 then output want4;&lt;/P&gt;&lt;P&gt; else if put(type,$diagx.) = 5 then output want5;&lt;/P&gt;&lt;P&gt; else if put(type,$diagx.) = 6 then output want6;&lt;/P&gt;&lt;P&gt; else if put(type,$diagx.) = 7 then output notfound;&lt;/P&gt;&lt;P&gt; else output error;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).&lt;/P&gt;&lt;P&gt;354:5 355:10 356:10 357:10 358:10 359:10 360:10&lt;/P&gt;&lt;P&gt;NOTE: There were 428 observations read from the data set SASHELP.CARS.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.WANT1 has 262 observations and 15 variables.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.WANT2 has 60 observations and 15 variables.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.WANT3 has 49 observations and 15 variables.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.WANT4 has 30 observations and 15 variables.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.WANT5 has 24 observations and 15 variables.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.WANT6 has 3 observations and 15 variables.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.NOTFOUND has 0 observations and 15 variables.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.ERROR has 0 observations and 15 variables.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;real time 1.21 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.20 seconds&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 13:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138866#M28009</guid>
      <dc:creator>jwillis</dc:creator>
      <dc:date>2014-04-30T13:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138867#M28010</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Everytime you have a succession of else if ..., you might consider using select:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select (put(type,$diagx.));&lt;/P&gt;&lt;P&gt;&amp;nbsp; when (1) output want1;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp; when (7) output notfound;&lt;/P&gt;&lt;P&gt;&amp;nbsp; otherwise output error;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's easier to read, and more efficient, because it has to do the put function only once.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 13:39:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138867#M28010</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2014-04-30T13:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138868#M28011</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data&lt;/P&gt;&lt;P&gt;&amp;nbsp; diags_78060&lt;/P&gt;&lt;P&gt;&amp;nbsp; .....&lt;/P&gt;&lt;P&gt;&amp;nbsp; diags_78791&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;set patients;&lt;/P&gt;&lt;P&gt;array a_dx dx_code1-dx_code41;&lt;/P&gt;&lt;P&gt;do i = 1 to dim(a_dx);&lt;/P&gt;&lt;P&gt;&amp;nbsp; select (a_dx(i));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; when ('78060') output diags_78060;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; when ('78791') output diags_78791;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; otherwise;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 13:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138868#M28011</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2014-04-30T13:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138869#M28012</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;Thank you for providing your suggestion!&amp;nbsp; My style suggestion is based on the "Comparisons" paragraph in the definition of the SELECT statement of the Dictionary of SAS statements in the SAS 9.3 Statements Reference book.&amp;nbsp; Page 343.&amp;nbsp; My style has become habit and I traditionally work with smaller datasets.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 14:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138869#M28012</guid>
      <dc:creator>jwillis</dc:creator>
      <dc:date>2014-04-30T14:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138870#M28013</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kurt, the code you provided above gives me fewer observations for each output dataset than the following code that I have been using:&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data diag1; set main;&lt;/P&gt;&lt;P&gt;array dx dx_code1-dx_code41;&lt;/P&gt;&lt;P&gt;flag=0;&lt;/P&gt;&lt;P&gt;do i=1 to dim(dx);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if dx(i) in: ('78060') then flag=1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;if flag&amp;gt;0 then output;&lt;/P&gt;&lt;P&gt;drop i flag;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I ended up putting the above code into a macro and typing 20 macro lines, changing the output dataset and the diagnosis code so that I get SAS to search the 41 diagnosis code fields for the first diagnosis code and output it to data set 1, then search the 41 diagnosis code fields for the second diagnoss code and output it to data set 2.&amp;nbsp; It seems inefficient but I guess it will work. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 14:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138870#M28013</guid>
      <dc:creator>chuakp</dc:creator>
      <dc:date>2014-04-30T14:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138871#M28014</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you familiar with BY processing?&lt;/P&gt;&lt;P&gt;You usually don't need to separate the diagnosis into separate files, unless its for final output. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your code uses the in: (in with colon) where 78060 will also match 780605 or 78060.3 for example, while Kurt's will only match exactly 78060. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 14:35:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138871#M28014</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-04-30T14:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138872#M28015</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi jwillis, I tried this approach, but the problem is that some of the values in the 41 diagnosis code variables are character variables like 'E19', and you can't use a PUT statement for them.&amp;nbsp; Most of the values are 5-digit numbers like 93819 but SAS trips up on the character variables.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 14:37:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138872#M28015</guid>
      <dc:creator>chuakp</dc:creator>
      <dc:date>2014-04-30T14:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138873#M28016</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I quota reeza's post:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, be careful with the in: as the matches may not be exactly what you want.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 14:39:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138873#M28016</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2014-04-30T14:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138874#M28017</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Reeza - since I'm only searching for one code, I changed to an equals sign instead of (in with colon).&amp;nbsp; Even after these change, the number of observations do not change in my output datasets.&amp;nbsp; Since diagnosis codes are five digits maximum (e.g., there is no 78060.5 value), I would not expecting that making this change would make a difference for five-digit codes like 78060.&amp;nbsp; In theory, a four-digit code like 7784 could be problematic if it matched both 77841 and 07784 (although empirically when I change to an equals sign, the number of observations don't change either).&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The reason I am wanting 20 output datasets is that I then am going to run proc freq's on each of them individually.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 14:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138874#M28017</guid>
      <dc:creator>chuakp</dc:creator>
      <dc:date>2014-04-30T14:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138875#M28018</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi chuakp,&lt;/P&gt;&lt;P&gt;I've encountered your issue in the past.&amp;nbsp; I'll see if I can dig up the code I wrote.&amp;nbsp; The problem I had was that SAS was interpreting the 'read from' input diagnosis code variable as numeric.&amp;nbsp; I was reading from EXCEL and the first 10 diagnosis positions were numeric so SAS said all the values in the EXCEL column were numeric.&amp;nbsp; The format statement should handle the E19 code if you code all the values in quotes.&amp;nbsp; If you can post&amp;nbsp; the error portion of your log or the proc contents output of your input dataset, I will be better able to advise you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 14:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138875#M28018</guid>
      <dc:creator>jwillis</dc:creator>
      <dc:date>2014-04-30T14:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138876#M28019</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Kurt, you and Reeza make a good point.&amp;nbsp; But that does not explain the discrepancy between the number of observations between the code I am now using (30933 observations) and the code you suggested (31082 observations).&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data diag1; set main;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;array dx dx_code1-dx_code41;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;flag=0;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;do i=1 to dim(dx);&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; if dx(i) = '78060' then flag=1;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;end;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if flag&amp;gt;0 then output;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;drop i flag;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 14:57:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138876#M28019</guid>
      <dc:creator>chuakp</dc:creator>
      <dc:date>2014-04-30T14:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138877#M28020</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, you could try the below, one thing I would check is what should happen if the code appears in more than one variable, say col1 and col2 both have 46611, should that row output twice or once?&amp;nbsp; The below outputs twice, however if you want it only once then change the if with the embedded output, to a select/when as KurtBremser has suggested.&amp;nbsp; The main perk with the below code is that it generates the code based on the data, so if you have lots of codes in a dataset, and lots of variables, the code doesn't need to change you can use that to generate the code (in this example I put the list in the do loop, however you could as easy have it in a dataset and put that I as a set).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;&amp;nbsp; attrib code1 code2 code3 code4 format=$20.;&lt;BR /&gt;&amp;nbsp; code1='7784'; code4='46611'; output;&lt;BR /&gt;&amp;nbsp; code2='7784'; code4='46611'; output;&lt;BR /&gt;&amp;nbsp; code1='7784'; code2='5990'; output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; select&amp;nbsp; distinct NAME&lt;BR /&gt;&amp;nbsp; into&amp;nbsp;&amp;nbsp;&amp;nbsp; :VAR_LIST separated by '","'&lt;BR /&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; SASHELP.VCOLUMN&lt;BR /&gt;&amp;nbsp; where&amp;nbsp;&amp;nbsp; LIBNAME="WORK" &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and MEMNAME="TEST";&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;data temp;&lt;BR /&gt;&amp;nbsp; do i= '78060','7784','4659','07999','46611','77989','5990';&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute('data code_'||strip(i)||';&lt;BR /&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set work.test;');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do j="&amp;amp;VAR_LIST.";&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute('if '||strip(j)||'="'||strip(i)||'" then output;');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute('run;'); &lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 14:57:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138877#M28020</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-04-30T14:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138878#M28021</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi jwillis, this is the code that I used based on your suggestion.&amp;nbsp; The proc format contains the 20 codes of interest - I want SAS to search the 41 diagnosis code variables for these 20 codes.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the log, I essentially get a deluge of the following error statements:&lt;/P&gt;&lt;P&gt;NOTE: Invalid numeric data, 'E9' , at line 3613 column 8.&lt;/P&gt;&lt;P&gt;NOTE: Invalid numeric data, 'V1' , at line 3613 column 8.&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc format;&lt;/P&gt;&lt;P&gt;value $ dxcodes&lt;/P&gt;&lt;P&gt;'78060' = 1&lt;/P&gt;&lt;P&gt;'7784' = 2&lt;/P&gt;&lt;P&gt;'4659' = 3&lt;/P&gt;&lt;P&gt;'07999' = 4&lt;/P&gt;&lt;P&gt;'46611' = 5&lt;/P&gt;&lt;P&gt;'77989' = 6&lt;/P&gt;&lt;P&gt;'5990' = 7&lt;/P&gt;&lt;P&gt;'53081' = 8&lt;/P&gt;&lt;P&gt;'27651' = 9&lt;/P&gt;&lt;P&gt;'77189' = 10&lt;/P&gt;&lt;P&gt;'46619' = 11&lt;/P&gt;&lt;P&gt;'79982' = 12&lt;/P&gt;&lt;P&gt;'77931' = 13&lt;/P&gt;&lt;P&gt;'7746' = 14&lt;/P&gt;&lt;P&gt;'V290' = 15&lt;/P&gt;&lt;P&gt;'77182' = 16&lt;/P&gt;&lt;P&gt;'7755' = 17&lt;/P&gt;&lt;P&gt;'V070' = 18&lt;/P&gt;&lt;P&gt;'6910' = 19&lt;/P&gt;&lt;P&gt;'78791' = 20;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;data want1 want2 want3 want4 want5 want6 want7 want8 want9 want10 want11 want12 want13 want14 want15 want16 want17 want18 want19 want20;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;set main;&lt;/P&gt;&lt;P&gt;array dx dx_code1-dx_code41;&lt;/P&gt;&lt;P&gt;flag=0;&lt;/P&gt;&lt;P&gt;do i=1 to dim(dx);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if put(dx(i), $dxcodes.)= 1 then flag=1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;if flag&amp;gt;0 then output;&lt;/P&gt;&lt;P&gt;drop i flag;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 15:01:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138878#M28021</guid>
      <dc:creator>chuakp</dc:creator>
      <dc:date>2014-04-30T15:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: Can a macro variable be a list of constants?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138879#M28022</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi RW9, diagnosis codes should not appear in more than one of the 41 diagnosis code fields.&amp;nbsp; Even if they did, I would only want the row to output once. Still, Kurt's code and my code are giving slightly different numbers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 15:04:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-a-macro-variable-be-a-list-of-constants/m-p/138879#M28022</guid>
      <dc:creator>chuakp</dc:creator>
      <dc:date>2014-04-30T15:04:27Z</dc:date>
    </item>
  </channel>
</rss>

