<?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: conditional use of %let? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/conditional-use-of-let/m-p/594391#M170763</link>
    <description>&lt;P&gt;As of SAS 9.4M5 released there is limited support for %IF/%THEN statements in open code. You must use %DO/%END block.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x= 1;
%if &amp;amp;x=1 %then %do;
  %let y= &amp;amp;x;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can&amp;nbsp; always use a data step for creating a macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  if symget('x')='1' then call symputx('y',symget('x'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use the IFN (or IFC) function with %SYSFUNC(), but then you would need to know what you want to set Y to when X is not 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 07 Oct 2019 01:19:29 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-10-07T01:19:29Z</dc:date>
    <item>
      <title>conditional use of %let?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-use-of-let/m-p/594377#M170757</link>
      <description>&lt;P&gt;Can I use %let statement conditionally outside of macro? Do I always have to define macro first and put %let inside if I want to use this with a certain condition?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, can I modify the second sentence so that it only works when x is equal to one? Then, the second sentence wouldn't work if 2 is given to x.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x= 1;
%let y= &amp;amp;x;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2019 22:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-use-of-let/m-p/594377#M170757</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2019-10-06T22:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: conditional use of %let?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-use-of-let/m-p/594386#M170762</link>
      <description>&lt;P&gt;The capability you are asking about depends on the release of SAS that you are using.&amp;nbsp; In recent updates to the software, you would be allowed to do this without having to define a macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x = 1;
%if &amp;amp;x=1 %then %let y = &amp;amp;x;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 06 Oct 2019 23:33:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-use-of-let/m-p/594386#M170762</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-10-06T23:33:50Z</dc:date>
    </item>
    <item>
      <title>Re: conditional use of %let?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-use-of-let/m-p/594391#M170763</link>
      <description>&lt;P&gt;As of SAS 9.4M5 released there is limited support for %IF/%THEN statements in open code. You must use %DO/%END block.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x= 1;
%if &amp;amp;x=1 %then %do;
  %let y= &amp;amp;x;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can&amp;nbsp; always use a data step for creating a macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  if symget('x')='1' then call symputx('y',symget('x'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use the IFN (or IFC) function with %SYSFUNC(), but then you would need to know what you want to set Y to when X is not 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 01:19:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-use-of-let/m-p/594391#M170763</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-07T01:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: conditional use of %let?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-use-of-let/m-p/594398#M170765</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/279507"&gt;@braam&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;If your SAS version/release doesn't yet allow open code macro statements mentioned by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;, you can do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;                                 
  if "&amp;amp;x" = "1" then call symputx ("y", "1") ;
run ;                                         
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but it's hardly better than using a macro. Or if the macro variable Y &lt;EM&gt;already exists&lt;/EM&gt;, you can do a simpler:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let y = %sysfunc (ifc (&amp;amp;x=1, 1, &amp;amp;y)) ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; If Y doesn't yet exist and X is not 1, it will result in a recursive error. But if you want Y to become 1 if X=1 and null otherwise regardless of whether Y already exists or not and/or its existing value, you can do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let y = %sysfunc (ifc (&amp;amp;x=1, 1,)) ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 08:46:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-use-of-let/m-p/594398#M170765</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-07T08:46:26Z</dc:date>
    </item>
  </channel>
</rss>

