<?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 Macrovariable for list of values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macrovariable-for-list-of-values/m-p/343128#M272910</link>
    <description>&lt;P&gt;Hello Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to call a macro variable in case statement in proc sql with list of values.&lt;/P&gt;&lt;P&gt;I have a table with all the list of values with column name - Empcode. I want to create a macro variable &amp;amp;empcd. which holds all the values within Empcode field ie "EM12","EM34" etc.&lt;/P&gt;&lt;P&gt;This then will be used in proc sql case statement ie&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;emp_list &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt; &lt;FONT color="#008080" face="Courier New" size="3"&gt;a.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;*,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;case&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;when&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;a.emp_id &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;in&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;empcd.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;"Match"&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; analysis&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;employee a&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I am thinking this as an alternative approach, rather than using 2 tables with left join to achieve the same output.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Many thanks.&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Mar 2017 00:58:44 GMT</pubDate>
    <dc:creator>ravimegharaj</dc:creator>
    <dc:date>2017-03-22T00:58:44Z</dc:date>
    <item>
      <title>Macrovariable for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macrovariable-for-list-of-values/m-p/343128#M272910</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to call a macro variable in case statement in proc sql with list of values.&lt;/P&gt;&lt;P&gt;I have a table with all the list of values with column name - Empcode. I want to create a macro variable &amp;amp;empcd. which holds all the values within Empcode field ie "EM12","EM34" etc.&lt;/P&gt;&lt;P&gt;This then will be used in proc sql case statement ie&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;emp_list &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt; &lt;FONT color="#008080" face="Courier New" size="3"&gt;a.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;*,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;case&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;when&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;a.emp_id &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;in&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;empcd.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;"Match"&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; analysis&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;employee a&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I am thinking this as an alternative approach, rather than using 2 tables with left join to achieve the same output.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Many thanks.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 00:58:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macrovariable-for-list-of-values/m-p/343128#M272910</guid>
      <dc:creator>ravimegharaj</dc:creator>
      <dc:date>2017-03-22T00:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: Macrovariable for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macrovariable-for-list-of-values/m-p/343133#M272911</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;HAVE (list of names in meta dataset and sashelp.class)
=======================================================

Up to 40 obs WORK.NAMES total obs=7

Obs    NAME

 1     James
 2     Jane
 3     Janet
 4     Jeffrey
 5     John
 6     Joyce
 7     Judy

SASHELP.CLASS
Up to 40 obs from sashelp.class total obs=19

Obs    NAME       SEX    AGE    HEIGHT    WEIGHT

  1    Alfred      M      14     69.0      112.5
  2    Alice       F      13     56.5       84.0
  3    Barbara     F      13     65.3       98.0
  4    Carol       F      14     62.8      102.5
  5    Henry       M      14     63.5      102.5
  6    James       M      12     57.3       83.0
...
 16    Robert      M      12     64.8      128.0
 17    Ronald      M      15     67.0      133.0
 18    Thomas      M      11     57.5       85.0
 19    William     M      15     66.5      112.0

WANT
====

NAME      SEX       AGE    HEIGHT    WEIGHT
-------------------------------------------
James     M          12      57.3        83
Jane      F          12      59.8      84.5
Janet     F          15      62.5     112.5
Jeffrey   M          13      62.5        84
John      M          12        59      99.5
Joyce     F          11      51.3      50.5
Judy      F          14      64.3        90

SOLUTION
========

* create the list of names;
data names;
 set sashelp.class(keep=name where=(name=: 'J'));
run;quit;

proc sql;
  select
     quote(name)
  into
    :names separated by ','
  from
     work.names;
  select
    *
  from
    sashelp.class
  where
    name in (&amp;amp;names);
;quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Mar 2017 01:12:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macrovariable-for-list-of-values/m-p/343133#M272911</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-03-22T01:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macrovariable for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macrovariable-for-list-of-values/m-p/343134#M272912</link>
      <description>&lt;P&gt;ok, consider that you have a table with employee id's then create the macro variable with list of employee id's in quotes and separated by the comma&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select distinct quote(Empcode) into: empcd separated by ',' from employeeids;
quit;

proc sql;
create table emp_list as select a.*,
case when a.emp_id in (&amp;amp;empcd.) then "Match" else " " end as analysis
from employee a;
quit;
&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;</description>
      <pubDate>Wed, 22 Mar 2017 01:14:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macrovariable-for-list-of-values/m-p/343134#M272912</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2017-03-22T01:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: Macrovariable for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macrovariable-for-list-of-values/m-p/343138#M272914</link>
      <description>&lt;P&gt;Hi Jag,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm getting white spaces between value and quote from first code ie "EMP12 ","EMP34 ", etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 01:25:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macrovariable-for-list-of-values/m-p/343138#M272914</guid>
      <dc:creator>ravimegharaj</dc:creator>
      <dc:date>2017-03-22T01:25:33Z</dc:date>
    </item>
    <item>
      <title>Re: Macrovariable for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macrovariable-for-list-of-values/m-p/343144#M272915</link>
      <description>&lt;P&gt;It does not matter, however if you want to eliminate the space trim(name) into.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 01:33:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macrovariable-for-list-of-values/m-p/343144#M272915</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-03-22T01:33:50Z</dc:date>
    </item>
  </channel>
</rss>

