<?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: why I cant get the text in %put in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/why-I-cant-get-the-text-in-put/m-p/875318#M10947</link>
    <description>&lt;P&gt;The macro language evaluates:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1 &amp;lt;= &amp;amp;date &amp;lt; 3&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As being&lt;/P&gt;
&lt;PRE&gt;(1 &amp;lt;= &amp;amp;date)  &amp;lt;  3&lt;/PRE&gt;
&lt;P&gt;In the macro language, you can't do that chained comparison thing.&amp;nbsp; Try:&lt;/P&gt;
&lt;PRE&gt;(1 &amp;lt;= &amp;amp;date) and (&amp;amp;date &amp;lt; 3)&lt;/PRE&gt;
&lt;P&gt;(Parentheses are optional here, but help clarify the intent.)&lt;/P&gt;</description>
    <pubDate>Thu, 11 May 2023 18:17:50 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2023-05-11T18:17:50Z</dc:date>
    <item>
      <title>why I cant get the text in %put</title>
      <link>https://communities.sas.com/t5/SAS-Studio/why-I-cant-get-the-text-in-put/m-p/875273#M10943</link>
      <description>&lt;P&gt;I'm wondering if I misunderstood the&amp;nbsp;%put macro statement.&lt;/P&gt;&lt;P&gt;Why I cant get "Option C" in my output table?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro testing;
%let g_nobs=100000;

%if &amp;amp;g_nobs = 0 %then %do;
	%put Option A;
%end;

%if 1 &amp;lt; &amp;amp;g_nobs and &amp;amp;g_nobs &amp;lt;= 10000 %then %do;
	%put Option B;
%end;

%if &amp;amp;g_nobs &amp;gt; 10000 %then %do;
	%put Option C;
%end;
%mend testing;



proc sql;
	create table haha (text char);
	insert into haha values ("&amp;amp;g_nobs");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 16:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/why-I-cant-get-the-text-in-put/m-p/875273#M10943</guid>
      <dc:creator>ChrisWoo</dc:creator>
      <dc:date>2023-05-11T16:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: why I cant get the text in %put</title>
      <link>https://communities.sas.com/t5/SAS-Studio/why-I-cant-get-the-text-in-put/m-p/875282#M10944</link>
      <description>&lt;P&gt;The %PUT statement is simply for writing values to the SAS log.&amp;nbsp; If you run the macro by submitting %testing, it will write Option C to the SAS log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It sound like you might be wanting to make a function-style macro that will return a bit of text, in this case it would return the text Option C, is that right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This macro will return the text Option C:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro foo;
  Option C
%mend foo;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could use like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro foo;
  Option C
%mend foo;

proc sql;
	create table haha (text char);
	insert into haha values ("%foo")
;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you the macro to decide which text to return based on some value, typically you would add a parameter to the macro rather than use a global macro variable.&amp;nbsp; This could be done like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro testing(nobs=);
%if &amp;amp;nobs = 0 %then %do;
	Option A  /*return*/
%end;
%else %if 1 &amp;lt; &amp;amp;nobs and &amp;amp;nobs &amp;lt;= 10000 %then %do;
	Option B  /*return*/
%end;
%else %if &amp;amp;nobs &amp;gt; 10000 %then %do;
 Option C   /*return*/
%end;
%mend testing;

proc sql;
	create table haha (text char);
	insert into haha values ("%testing(nobs=0)")     ;
	insert into haha values ("%testing(nobs=5000)")  ;
	insert into haha values ("%testing(nobs=15000)") ;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 16:30:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/why-I-cant-get-the-text-in-put/m-p/875282#M10944</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-05-11T16:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: why I cant get the text in %put</title>
      <link>https://communities.sas.com/t5/SAS-Studio/why-I-cant-get-the-text-in-put/m-p/875285#M10945</link>
      <description>&lt;P&gt;Also, the macro variable g_nobs is LOCAL to the macro testing. So it no longer exists after the %testing macro stops executing.&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 16:38:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/why-I-cant-get-the-text-in-put/m-p/875285#M10945</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-11T16:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: why I cant get the text in %put</title>
      <link>https://communities.sas.com/t5/SAS-Studio/why-I-cant-get-the-text-in-put/m-p/875308#M10946</link>
      <description>&lt;P&gt;I would like to seek your help again on my %if condition.&lt;/P&gt;&lt;P&gt;I tried to modified abit from previous code, but why I cant get my result "F" even if today_day = 12.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let PrevMonth = %sysfunc(intnx(month,%sysfunc(today()),-1,s),mmddyy2.);
%let Today_day = %sysfunc(intnx(day,%sysfunc(today()),0,s),ddmmyy2.);&lt;BR /&gt;
%macro testing(date=&amp;amp;Today_day);
%if 1 &amp;lt;= &amp;amp;date &amp;lt; 3 %then %do;
	T  /*return*/
%end;
%else %if 3 &amp;lt;= &amp;amp;date &amp;lt;= 31 %then %do;
	F  /*return*/
%end;
%mend testing;

proc sql;
	create table haha (text char);
	insert into haha values ("%testing(date=&amp;amp;today_day)");
quit ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 May 2023 17:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/why-I-cant-get-the-text-in-put/m-p/875308#M10946</guid>
      <dc:creator>ChrisWoo</dc:creator>
      <dc:date>2023-05-11T17:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: why I cant get the text in %put</title>
      <link>https://communities.sas.com/t5/SAS-Studio/why-I-cant-get-the-text-in-put/m-p/875318#M10947</link>
      <description>&lt;P&gt;The macro language evaluates:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1 &amp;lt;= &amp;amp;date &amp;lt; 3&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As being&lt;/P&gt;
&lt;PRE&gt;(1 &amp;lt;= &amp;amp;date)  &amp;lt;  3&lt;/PRE&gt;
&lt;P&gt;In the macro language, you can't do that chained comparison thing.&amp;nbsp; Try:&lt;/P&gt;
&lt;PRE&gt;(1 &amp;lt;= &amp;amp;date) and (&amp;amp;date &amp;lt; 3)&lt;/PRE&gt;
&lt;P&gt;(Parentheses are optional here, but help clarify the intent.)&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 18:17:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/why-I-cant-get-the-text-in-put/m-p/875318#M10947</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-05-11T18:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: why I cant get the text in %put</title>
      <link>https://communities.sas.com/t5/SAS-Studio/why-I-cant-get-the-text-in-put/m-p/875322#M10948</link>
      <description>&lt;P&gt;Side note, if just want to see what the macro returns, that is when you can use a %PUT statement, outside of the macro.&amp;nbsp; So instead of using SQL to see a value, you can run the macro and look at your log.&amp;nbsp; Code like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro testing(date= );
%if (1 &amp;lt;= &amp;amp;date) and (&amp;amp;date &amp;lt; 3) %then %do;
	T  /*return*/
%end;
%else %if (3 &amp;lt;= &amp;amp;date) and (&amp;amp;date &amp;lt;= 31) %then %do;
	F  /*return*/
%end;
%mend testing;

%put date=2 returns: %testing(date=2) ;
%put date=8 returns: %testing(date=8) ;
%put date=today() returns: %testing(date=%sysfunc(day(%sysfunc(today()))) ) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 18:24:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/why-I-cant-get-the-text-in-put/m-p/875322#M10948</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-05-11T18:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: why I cant get the text in %put</title>
      <link>https://communities.sas.com/t5/SAS-Studio/why-I-cant-get-the-text-in-put/m-p/875395#M10949</link>
      <description>Thx, that is helpful</description>
      <pubDate>Fri, 12 May 2023 03:30:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/why-I-cant-get-the-text-in-put/m-p/875395#M10949</guid>
      <dc:creator>ChrisWoo</dc:creator>
      <dc:date>2023-05-12T03:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: why I cant get the text in %put</title>
      <link>https://communities.sas.com/t5/SAS-Studio/why-I-cant-get-the-text-in-put/m-p/875403#M10950</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Also, the macro variable g_nobs is LOCAL to the macro testing. So it no longer exists after the %testing macro stops executing.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That macro did NOT define G_NOBS as LOCAL.&amp;nbsp; It will only create a local macro variable if there is not already a macro variable with that name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you want to see the value after the macro has finished running just make sure you have created a macro variable named G_NOBS before you call the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 06:38:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/why-I-cant-get-the-text-in-put/m-p/875403#M10950</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-12T06:38:34Z</dc:date>
    </item>
  </channel>
</rss>

