<?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: Assign as values of a parameter of a macro the values a variable takes in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Assign-as-values-of-a-parameter-of-a-macro-the-values-a-variable/m-p/984595#M43722</link>
    <description>&lt;P&gt;Your SITEID variable is character.&lt;/P&gt;
&lt;P&gt;The code you generated was&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where &amp;amp;myVar in (002 003);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which is trying to look for a character value in a list of numeric values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To make string literals add quotes.&lt;/P&gt;
&lt;P&gt;Best to use single quotes so that macro triggers in the values of SITEID are not acted on by the macro processor.&lt;/P&gt;
&lt;P&gt;Note that trailing spaces are not meaningful in comparisons, but would make the text put into the macro variable longer, so remove those.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct quote(trim(SITEID),"'")
  into :SITES separated by ' ' 
  from DB
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Mar 2026 13:50:51 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2026-03-11T13:50:51Z</dc:date>
    <item>
      <title>Assign as values of a parameter of a macro the values a variable takes</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assign-as-values-of-a-parameter-of-a-macro-the-values-a-variable/m-p/984588#M43720</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following dataset:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
infile datalines;
input ID $ subgrp $ siteid $;
datalines;
001 Y 002
002 N 002
003 N 002
004 Y 002
005 Y 003
006 N 003
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would like to give as input values (value_myVar) of my variable (myVar),&amp;nbsp; the list of sites (siteid). Since they are not unique because there are multiple records per ID, I did the following:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;select distinct siteid into :sites separated by ' ' from db;quit;
%put &amp;amp;sites; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then I have a macro that looks like this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%mymacro(data=db, myVar=siteid, value_myVar=&amp;amp;sites, out=test);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the macro there is the following condition:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where &amp;amp;myVar in (&amp;amp;value_myVar);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This was initially intended to select "Y" or "N". In this case the variable takes different values I cannot manually specify because I don't know every time how many and which are.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I thought to put all values in &amp;amp;sites to allow the macro to read all available siteids independently from what is my actual knowledge and to run (proc freq) on all of them.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following error occurs:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: WHERE clause operator requires compatible variables.&lt;/P&gt;
&lt;P&gt;I suppose because the &amp;amp;sites content looks like this: 002 003 and where requires: "002", "003" etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help me please?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One note: the output should be the output of proc freq with all sites as rows and relative statistics.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally I cannot remove the "where" condition from the code because in other cases I need to specify "Y" or "N".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2026 13:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assign-as-values-of-a-parameter-of-a-macro-the-values-a-variable/m-p/984588#M43720</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2026-03-11T13:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: Assign as values of a parameter of a macro the values a variable takes</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assign-as-values-of-a-parameter-of-a-macro-the-values-a-variable/m-p/984589#M43721</link>
      <description>&lt;P&gt;Try the following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;994  proc sql noprint;
995  select distinct quote(trim(siteid)) into :sites separated by ' '
996  from db;
997  quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


998
999  %put &amp;amp;sites;
"002" "003"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Mar 2026 13:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assign-as-values-of-a-parameter-of-a-macro-the-values-a-variable/m-p/984589#M43721</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2026-03-11T13:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: Assign as values of a parameter of a macro the values a variable takes</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assign-as-values-of-a-parameter-of-a-macro-the-values-a-variable/m-p/984595#M43722</link>
      <description>&lt;P&gt;Your SITEID variable is character.&lt;/P&gt;
&lt;P&gt;The code you generated was&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where &amp;amp;myVar in (002 003);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which is trying to look for a character value in a list of numeric values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To make string literals add quotes.&lt;/P&gt;
&lt;P&gt;Best to use single quotes so that macro triggers in the values of SITEID are not acted on by the macro processor.&lt;/P&gt;
&lt;P&gt;Note that trailing spaces are not meaningful in comparisons, but would make the text put into the macro variable longer, so remove those.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct quote(trim(SITEID),"'")
  into :SITES separated by ' ' 
  from DB
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2026 13:50:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assign-as-values-of-a-parameter-of-a-macro-the-values-a-variable/m-p/984595#M43722</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-03-11T13:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: Assign as values of a parameter of a macro the values a variable takes</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assign-as-values-of-a-parameter-of-a-macro-the-values-a-variable/m-p/984597#M43723</link>
      <description>If the WHERE statement is part of a DATA step, it is much better to use a hash object there. A macro variable will reach its maximum size much earlier than a hash object would run out of memory. Note that the hash object can also be used in a DATA step view that serves as input for a procedure.</description>
      <pubDate>Wed, 11 Mar 2026 13:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assign-as-values-of-a-parameter-of-a-macro-the-values-a-variable/m-p/984597#M43723</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2026-03-11T13:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: Assign as values of a parameter of a macro the values a variable takes</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assign-as-values-of-a-parameter-of-a-macro-the-values-a-variable/m-p/984629#M43724</link>
      <description>&lt;P&gt;You could change your WHERE statement&lt;/P&gt;
&lt;PRE&gt;where &amp;amp;myVar in (&amp;amp;value_myVar);&lt;/PRE&gt;
&lt;P&gt;into&lt;/P&gt;
&lt;PRE&gt;where  &lt;STRONG&gt;findw&lt;/STRONG&gt;("&amp;amp;value_myVar"，"&amp;amp;myVar" ,' ','it');&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Mar 2026 07:19:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assign-as-values-of-a-parameter-of-a-macro-the-values-a-variable/m-p/984629#M43724</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-03-12T07:19:52Z</dc:date>
    </item>
  </channel>
</rss>

