<?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 variable in infile statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-infile-statement/m-p/916408#M360960</link>
    <description>&lt;P&gt;oh assuming all the macro variable are setup correctly etc&lt;/P&gt;
&lt;P&gt;does infile statement allows macro variable being inside quotation mark?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Feb 2024 07:12:33 GMT</pubDate>
    <dc:creator>HeatherNewton</dc:creator>
    <dc:date>2024-02-16T07:12:33Z</dc:date>
    <item>
      <title>macro variable in infile statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-infile-statement/m-p/916403#M360956</link>
      <description>&lt;P&gt;hi I have some macro variable&amp;nbsp;&lt;/P&gt;
&lt;P&gt;e.g.&lt;/P&gt;
&lt;PRE&gt;%let sampdate = $g_job_date;
data _null_;
yyyymmdd_L6=intnx('month',"$SAMPDATE."d,-6,'end');
call symput("YYYYMMDD_L6",PUT(YYMMDD_L6,YYMMDDN8.));
run;

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;now my questions is does it get interpreted correctly inside infile statement like below:&lt;/P&gt;
&lt;P&gt;data monthly.pd_pool;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;infile "/boccc/miu/interface/monthly.pd_pool_id_&amp;amp;yyyymmdd_L6.";&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;let's say &amp;amp;yyyymmdd_L6. is 20231130&lt;/P&gt;
&lt;P&gt;from infile statement&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;infile "/boccc/miu/interface/monthly.pd_pool_id_&amp;amp;yyyymmdd_L6.";&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;does SAS know he has to retrieve the file&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;monthly.pd_pool_id_20231130&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 06:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-infile-statement/m-p/916403#M360956</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2024-02-16T06:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in infile statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-infile-statement/m-p/916404#M360957</link>
      <description>&lt;P&gt;What should that $ do in front of macro variable names?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 06:47:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-infile-statement/m-p/916404#M360957</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2024-02-16T06:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in infile statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-infile-statement/m-p/916406#M360959</link>
      <description>&lt;P&gt;Did you try it and see?&lt;/P&gt;
&lt;P&gt;Or even just try a %PUT statement to show the resolved value of the given statement.&lt;/P&gt;
&lt;P&gt;If you have a question about a specific macro variable will resolve in a statement use %put and look in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let yyyymmdd_L6=20231130;

%put infile "/boccc/miu/interface/monthly.pd_pool_id_&amp;amp;yyyymmdd_L6.";&lt;/PRE&gt;
&lt;P&gt;Since you do not show an example of how you may be combining elements in your infile statement hard to say anything else.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do say that this raises all sorts of questions about what you are actually attempting:&lt;/P&gt;
&lt;PRE&gt;%let sampdate = $g_job_date;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;$g_job_date is not a macro variable and your data step does not use the Sampdate macro variable created. That would be using a "&amp;amp;sampdate" not "$sampdate".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;hi I have some macro variable&amp;nbsp;&lt;/P&gt;
&lt;P&gt;e.g.&lt;/P&gt;
&lt;PRE&gt;%let sampdate = $g_job_date;
data _null_;
yyyymmdd_L6=intnx('month',"$SAMPDATE."d,-6,'end');
call symput("YYYYMMDD_L6",PUT(YYMMDD_L6,YYMMDDN8.));
run;

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;now my questions is does it get interpreted correctly inside infile statement like below:&lt;/P&gt;
&lt;P&gt;data monthly.pd_pool;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;infile "/boccc/miu/interface/monthly.pd_pool_id_&amp;amp;yyyymmdd_L6.";&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;let's say &amp;amp;yyyymmdd_L6. is 20231130&lt;/P&gt;
&lt;P&gt;from infile statement&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;infile "/boccc/miu/interface/monthly.pd_pool_id_&amp;amp;yyyymmdd_L6.";&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;does SAS know he has to retrieve the file&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;monthly.pd_pool_id_20231130&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;?&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 06:57:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-infile-statement/m-p/916406#M360959</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-02-16T06:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in infile statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-infile-statement/m-p/916408#M360960</link>
      <description>&lt;P&gt;oh assuming all the macro variable are setup correctly etc&lt;/P&gt;
&lt;P&gt;does infile statement allows macro variable being inside quotation mark?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 07:12:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-infile-statement/m-p/916408#M360960</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2024-02-16T07:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in infile statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-infile-statement/m-p/916412#M360961</link>
      <description>&lt;P&gt;I am very sure we have covered this with you before.&lt;/P&gt;
&lt;P&gt;Macro triggers (% and &amp;amp;) are resolved when enclosed in double quotes.&lt;/P&gt;
&lt;P&gt;Macro triggers are NOT resolved when enclosed in single quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Special case:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;infile "some command '&amp;amp;complex_parameter.'" pipe;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here the macro trigger will be resolved, as the outer double quotes also mask the single quotes.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 08:05:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-infile-statement/m-p/916412#M360961</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-16T08:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in infile statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-infile-statement/m-p/916449#M360976</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;oh assuming all the macro variable are setup correctly etc&lt;/P&gt;
&lt;P&gt;does infile statement allows macro variable being inside quotation mark?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The SAS language allows macro variables to be resolved inside &lt;EM&gt;double&lt;/EM&gt; quotation marks.&amp;nbsp; To test it out, you can use the %PUT statement, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let yyyymmdd=20231130 ;
%put "/boccc/miu/interface/monthly.pd_pool_id_&amp;amp;yyyymmdd_L6.";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will see that that code does not work you get:&lt;/P&gt;
&lt;PRE&gt;1    %let yyyymmdd=20231130 ;
2    %put "/boccc/miu/interface/monthly.pd_pool_id_&amp;amp;yyyymmdd_L6.";
WARNING: Apparent symbolic reference YYYYMMDD_L6 not resolved.
"/boccc/miu/interface/monthly.pd_pool_id_&amp;amp;yyyymmdd_L6."
&lt;/PRE&gt;
&lt;P&gt;So SAS looked for a macro variable named YYYYMMDD_L6, which does not exist.&amp;nbsp; The answer here is to add a dot after the name of the macro variable, to tell the macro processor that the name of the macro variable has ended.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you add a dot, the log will show that the code works:&lt;/P&gt;
&lt;PRE&gt;5    %let yyyymmdd=20231130 ;
6    %put "/boccc/miu/interface/monthly.pd_pool_id_&amp;amp;yyyymmdd._L6.";
"/boccc/miu/interface/monthly.pd_pool_id_20231130_L6."
&lt;/PRE&gt;
&lt;P&gt;You don't have to worry about any special rules relating to the INPUT statement, or any other SAS statement when you want to use a macro variable.&amp;nbsp; SAS statements do not have any interaction with the macro language.&amp;nbsp; &amp;nbsp;The macro language is generating SAS code.&amp;nbsp; So for examples like this, it's helpful to test your macro code with a simple %PUT statement, which will allow you to see the code generated by the macro language.&amp;nbsp; If that code looks good, then you can use it anywhere.&amp;nbsp; So you can be confident that you could do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;infile "/boccc/miu/interface/monthly.pd_pool_id_&amp;amp;yyyymmdd._L6.";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;title "Data for monthly.pd_pool_id_&amp;amp;yyyymmdd._L6.";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  date=input("&amp;amp;yyyymmdd",yymmdd8.) ;
  format date date9. ;
  put date= ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 13:57:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-infile-statement/m-p/916449#M360976</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-02-16T13:57:47Z</dc:date>
    </item>
  </channel>
</rss>

