<?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: macro parameter in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713720#M27212</link>
    <description>&lt;P&gt;As the error message says you cannot just call a function in the middle of PUT statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So this is invalid:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put quote(somevariable);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you call the MACRO function %SYSFUNC() then that will happen BEFORE the code is passed onto SAS to interpret. So code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put %sysfunc(quote(&amp;amp;list));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Get's converted to&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put """A"" ""B"" ""C""";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which will result in this being written by the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"A" "B" "C"&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 24 Jan 2021 18:54:41 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-01-24T18:54:41Z</dc:date>
    <item>
      <title>macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713565#M27177</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question about macro. I try to print dataset&amp;nbsp;sasuser.admit with name="Murray, W"; the name value can be replaced, for example, it can be&amp;nbsp;"Murray, W" or "Almers, C" next time. I wrote a macro, but something is wrong. My code is following:&lt;/P&gt;&lt;PRE&gt;%macro output(name=);
title "print dataset with name: &amp;amp;name";
proc print data=sasuser.admit;
   where name  in ("&amp;amp;name");
run;
%mend output;

%macro output(name=%str(Murray, W))&lt;/PRE&gt;&lt;P&gt;But no result came out. Any suggestion? Furthermore, when name in ("Murray, W", "Almers, C"), how to do it? Thanks.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2021 05:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713565#M27177</guid>
      <dc:creator>lc7033907</dc:creator>
      <dc:date>2021-01-23T05:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713566#M27178</link>
      <description>&lt;P&gt;Show the Proc print that worked correctly without any macro variables.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2021 05:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713566#M27178</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-23T05:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713571#M27180</link>
      <description>&lt;P&gt;Maybe the comma in the name makes an issue.&lt;/P&gt;
&lt;P&gt;1) Please post few lines from your input using data step with infile statement&lt;/P&gt;
&lt;P&gt;2) What do you mean by "&lt;SPAN&gt;But no result came out." ?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; Are you sure there is a name "Murray, W" in the input? No case issue?&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Whole characters given?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3) You are comparing just one variable so you can replace &lt;STRONG&gt;in&lt;/STRONG&gt; by&amp;nbsp;&lt;STRONG&gt;=&lt;/STRONG&gt; in the&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; where statement&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2021 07:21:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713571#M27180</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-23T07:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713580#M27181</link>
      <description>Quoted characters in a WHERE comparison can be parsed incorrectly.  Try:&lt;BR /&gt;&lt;BR /&gt;where name in ("%unquote(&amp;amp;name)");</description>
      <pubDate>Sat, 23 Jan 2021 10:01:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713580#M27181</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-01-23T10:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713599#M27183</link>
      <description>&lt;P&gt;Thanks for all help. Let me describe my question more clearly:&lt;/P&gt;&lt;PRE&gt;data admit;
  input ID $4. Name :&amp;amp;$14. @23 Sex $1. Age Date Height Weight Actlevel $4. Fee 7.2;
  datalines;
2458 Murry. W         M 27 1 72 168 HIGH 85.20
2462 Almers. C        F 34 3 66 152 HIGH 124.80
2501 Bonaventure, T   F 31 17 61 123 LOW 149.75
2523 Johnson, R       F 43 31 63 137 MOD 149.75
2539 LaMance, K       M 51 4 71 158 LOW 124.80
2544 Jones, M         M 29 6 76 193 HIGH 124.80
;
 
proc print data=admit;
where name="Murry. W";
title "print dataset with name: Murry. W";
run;

proc print data=admit;
where name in ("Murry. W", "Almers. C");
title "print dataset with name: Murry. W, Almers. C";
run;&lt;/PRE&gt;&lt;P&gt;I have a dataset, called admit, and i want to print some records with where statement. The value of name can be one, like the first proc print; the name value might be two, like second print. Now I want to write a macro to combine these two cases. My macro is in the following:&lt;/P&gt;&lt;PRE&gt;options symbolgen;
%macro output(name=);
title "print dataset with name: &amp;amp;name";
proc print data=admit;
   where name  in ("&amp;amp;name");
run;
%mend output;

%macro output(name=Murry. W)&lt;/PRE&gt;&lt;P&gt;But when I invoke the above macro, nothing comes out and even there is nothing showing up in LOG, so something must be wrong. Any suggestions? Thanks.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2021 15:34:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713599#M27183</guid>
      <dc:creator>lc7033907</dc:creator>
      <dc:date>2021-01-23T15:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713611#M27184</link>
      <description>&lt;P&gt;You can use any of both next methods:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*1*/
%let names = 'Murry. W'  'Almers. C';
proc print data=admit(where=(name in(&amp;amp;names))); 
run;

/*2*/
%macro output(name=);
	title "Print dataset for &amp;amp;name";
	proc print data=admit(where=(name in(&amp;amp;name))); 
	run;
%mend output;
%output(name='Murry. W'  'Almers. C');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Pay attention, names need be quoted with single quotes.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2021 18:46:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713611#M27184</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-23T18:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713630#M27186</link>
      <description>&lt;P&gt;Probably best to just put the quotes into the values passed to the macro.&amp;nbsp; (Also do not include %MACRO when CALLING the macro as that is instead an attempt to re-create the macro).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro output(name=);
title "print dataset with name: " %sysfunc(quote(&amp;amp;name));
proc print data=admit;
   where name in (&amp;amp;name);
run;
%mend output;

%output(name="Murry. W")
%output(name="Murry. W" "Almers. C")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2021 21:39:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713630#M27186</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-23T21:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713638#M27189</link>
      <description>&lt;P&gt;Why your attempt doesn't work:&lt;/P&gt;
&lt;P&gt;When you have this&lt;/P&gt;
&lt;PRE&gt;proc print data=admit;
   where name  in ("&amp;amp;name");
run;&lt;/PRE&gt;
&lt;P&gt;And name is&lt;/P&gt;
&lt;PRE&gt;Murry. W, Almers. C&lt;/PRE&gt;
&lt;P&gt;Then the Proc print resolves to&lt;/P&gt;
&lt;PRE&gt;proc print data=admit;
   where name  in ("Murry. W, Almers. C");
run;&lt;/PRE&gt;
&lt;P&gt;Which is not the same as the code that executes because &lt;STRONG&gt;each separate value&lt;/STRONG&gt; in the IN comparison needs to be separately quoted.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2021 22:10:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713638#M27189</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-23T22:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713684#M27196</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello Shmuel, thanks. I tried your two ways and they both work perfect. One more thing, why do we need single quotation marks ' '? Could you please give me some explanation? Thanks.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 15:14:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713684#M27196</guid>
      <dc:creator>lc7033907</dc:creator>
      <dc:date>2021-01-24T15:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713685#M27197</link>
      <description>&lt;P&gt;Hello Tom, thanks. Your way also worked perfectly. But I know nothing about %sysfunc and %qsysfunc, could you explain them? Thank you very much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 15:17:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713685#M27197</guid>
      <dc:creator>lc7033907</dc:creator>
      <dc:date>2021-01-24T15:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713687#M27198</link>
      <description>&lt;P&gt;Yes, you are right,&amp;nbsp;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884" target="_blank" rel="noopener"&gt;ballardw&lt;/A&gt;. Actually I realized this point, but I don't know how to correct it, I mean how to use a macro to solve this problem. Now I got ideas from this post, thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 15:28:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713687#M27198</guid>
      <dc:creator>lc7033907</dc:creator>
      <dc:date>2021-01-24T15:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713692#M27201</link>
      <description>&lt;P&gt;Read the documentation on &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=p1o13d7wb2zfcnn19s5ssl2zdxvi.htm&amp;amp;locale=en" target="_self"&gt;sysfunc&lt;/A&gt;&amp;nbsp;and &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p059exu866hqw2n0zw9aoxf3p6oj.htm&amp;amp;locale=en" target="_self"&gt;quote&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Or just try it out.&lt;/P&gt;
&lt;PRE&gt;151   %let list="A" "B" "C";
152
153   data _null_;
154     put &amp;amp;list ;
155     put %sysfunc(quote(&amp;amp;list));
156   run;

ABC
"A" "B" "C"
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 15:47:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713692#M27201</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-24T15:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713703#M27203</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361912"&gt;@lc7033907&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;Hello Shmuel, thanks. I tried your two ways and they both work perfect. One more thing, why do we need single quotation marks ' '? Could you please give me some explanation? Thanks.&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Look at net line:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;title "Print dataset for &amp;amp;name";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Suppose name is defined with double quotes, as "xxxxx" then above line will be interpreted as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;title "Print dataset for "xxxxx"";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which is erroneous. With single quotes it will show:.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;title "Print dataset for 'xxxxx'";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Jan 2021 17:10:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713703#M27203</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-24T17:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713705#M27205</link>
      <description>&lt;P&gt;Or just let the QUOTE() function figure out how to handle any potential embedded quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;title %sysfunc(quote(Print dataset for &amp;amp;name));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Jan 2021 17:49:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713705#M27205</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-24T17:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713707#M27206</link>
      <description>&lt;P&gt;I see, thank you so much. I really appreciate.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 17:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713707#M27206</guid>
      <dc:creator>lc7033907</dc:creator>
      <dc:date>2021-01-24T17:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713708#M27207</link>
      <description>&lt;P&gt;Thank you, Tom. I see. %sysfunc(quote()) can keep macro values as what they are, including " " . I also tried just&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; put quote(&amp;amp;list);&lt;/PRE&gt;
&lt;P&gt;but error occurs&lt;/P&gt;
&lt;P&gt;1 "A" "B" "C"&lt;BR /&gt;---&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, arrayname, _ALL_, _CHARACTER_,&lt;BR /&gt;_CHAR_, _NUMERIC_.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems %sysfunc is needed in macro invocation when quoting something. Thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 18:02:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713708#M27207</guid>
      <dc:creator>lc7033907</dc:creator>
      <dc:date>2021-01-24T18:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713720#M27212</link>
      <description>&lt;P&gt;As the error message says you cannot just call a function in the middle of PUT statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So this is invalid:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put quote(somevariable);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you call the MACRO function %SYSFUNC() then that will happen BEFORE the code is passed onto SAS to interpret. So code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put %sysfunc(quote(&amp;amp;list));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Get's converted to&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put """A"" ""B"" ""C""";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which will result in this being written by the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"A" "B" "C"&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Jan 2021 18:54:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713720#M27212</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-24T18:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713745#M27215</link>
      <description>&lt;P&gt;Thank you, Tom. Now I am much clearer about these macro functions. Really appreciate.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 20:44:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-parameter/m-p/713745#M27215</guid>
      <dc:creator>lc7033907</dc:creator>
      <dc:date>2021-01-24T20:44:00Z</dc:date>
    </item>
  </channel>
</rss>

