<?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: What does this statement say and does? Global….. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-does-this-statement-say-and-does-Global/m-p/848787#M335566</link>
    <description>&lt;P&gt;Let's do it line by line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%maco check;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That should be&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=" language-sas"&gt;%macro check;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And it begins the definition of a macro named CHECK.&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=" language-sas"&gt;%global exists findparm; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That will force two macro variables, EXISTS and FINDPARM, into the GLOBAL macro scope.&amp;nbsp; If there such macro variables do not exist there values will be empty strings.&amp;nbsp; If they exist and are already GLOBAL then nothing changes.&amp;nbsp; If they exist but are LOCAL to some other macro that has called this %CHECK macro then you will get an ERROR message.&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=" language-sas"&gt;%let exists=%sysfunc(exist(mypath.dataset));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That assigns a value to the EXISTS macro.&amp;nbsp; It will be the result of calling the SAS function EXIST() ,via the macro function %SYSFUNC(), to test if the dataset DATASET exists in the library pointed to by the MYPATH libref.&amp;nbsp; The value will be either 1 (TRUE) or 0 (FALSE).&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=" language-sas"&gt;%if &amp;amp;exist %then %do; 
  %let findparm = -type f - newer &amp;amp;thatpath/dataset.sas7bdat;
%end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That will conditionally set the value of the FINDPARM macro variable.&amp;nbsp; If the value in EXIST is TRUE then FINDPARM is going to be set to the string that starts with a hyphen.&amp;nbsp; &amp;nbsp;Looks like they are perhaps command line options that will be used latter with some Unix command.&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=" language-sas"&gt;%else %do;
  %let findparm= -type f; 
%end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But when the dataset did not exist it just set FINDPARM to that shorter string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That should be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which marks the end of the definition of the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have defined the macro you can then call it using&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%check&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And it will update (and possibly create) the two macro variables based on whether or not the dataset exists.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Read about the scoping of macro variables&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1b76sxg9dbcyrn1l5age5j5nvgw.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1b76sxg9dbcyrn1l5age5j5nvgw.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A macro variable that is in the LOCAL scope of the macro disappears when the macro finishes. The reason to use %GLOBAL is to ensure that the values assigned while teh macro runs are available after the macro has finished running.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that another way to make sure the macro variable's value exists after the macro finishes running is to define the macro variable before calling the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To avoid the error that would occur if the macro variables already existed as LOCAL to some other macro that is calling %CHECK you should only conditionally run the %GLOBAL statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if not %symexist(exists) %then %global exists;
%if not %symexist(findparm) %then %global findparm; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Dec 2022 19:18:19 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-12-09T19:18:19Z</dc:date>
    <item>
      <title>What does this statement say and does? Global…..</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-this-statement-say-and-does-Global/m-p/848779#M335562</link>
      <description>&lt;P&gt;%maco check;&lt;/P&gt;
&lt;P&gt;%global exists findparm;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let exists=%sysfunc(exist(mypath.dataset));&lt;/P&gt;
&lt;P&gt;%if &amp;amp;exist %then %do;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let findparm = -type f - newer &amp;amp;thatpath/dataset.sas7bdat;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;%else %do;&lt;/P&gt;
&lt;P&gt;%let findparm= -type f;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone explain line by line please?&lt;/P&gt;
&lt;P&gt;Respectfully ,&lt;/P&gt;
&lt;P&gt;blue blue&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 18:45:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-this-statement-say-and-does-Global/m-p/848779#M335562</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-12-09T18:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: What does this statement say and does? Global…..</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-this-statement-say-and-does-Global/m-p/848781#M335564</link>
      <description>&lt;P&gt;Macro variables named &amp;amp;EXISTS and &amp;amp;FINDPARM can be accessed outside the macro in which they were created. If there was no %GLOBAL statement, then these two macro variables could NOT be accessed outside the macro in which they were created.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%let exists=&lt;/FONT&gt; determines if the data set exists, and assigns a 1 if so and a zero otherwise&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;%if &amp;amp;exists&lt;/FONT&gt; if this is equal to 1, then certain commands are executed; otherwise other commands are executed. (Typo was fixed by me, the original code uses &amp;amp;exist which doesn't have a value)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%let findparm=&lt;/FONT&gt; assigns a text string to the macro variable&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 18:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-this-statement-say-and-does-Global/m-p/848781#M335564</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-09T18:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: What does this statement say and does? Global…..</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-this-statement-say-and-does-Global/m-p/848783#M335565</link>
      <description>&lt;P&gt;Maxim 1.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1lhhti7fjxgb1n1fuiubqk11h4d.htm" target="_blank" rel="noopener"&gt;%GLOBAL&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 19:00:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-this-statement-say-and-does-Global/m-p/848783#M335565</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-12-09T19:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: What does this statement say and does? Global…..</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-this-statement-say-and-does-Global/m-p/848787#M335566</link>
      <description>&lt;P&gt;Let's do it line by line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%maco check;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That should be&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=" language-sas"&gt;%macro check;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And it begins the definition of a macro named CHECK.&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=" language-sas"&gt;%global exists findparm; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That will force two macro variables, EXISTS and FINDPARM, into the GLOBAL macro scope.&amp;nbsp; If there such macro variables do not exist there values will be empty strings.&amp;nbsp; If they exist and are already GLOBAL then nothing changes.&amp;nbsp; If they exist but are LOCAL to some other macro that has called this %CHECK macro then you will get an ERROR message.&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=" language-sas"&gt;%let exists=%sysfunc(exist(mypath.dataset));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That assigns a value to the EXISTS macro.&amp;nbsp; It will be the result of calling the SAS function EXIST() ,via the macro function %SYSFUNC(), to test if the dataset DATASET exists in the library pointed to by the MYPATH libref.&amp;nbsp; The value will be either 1 (TRUE) or 0 (FALSE).&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=" language-sas"&gt;%if &amp;amp;exist %then %do; 
  %let findparm = -type f - newer &amp;amp;thatpath/dataset.sas7bdat;
%end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That will conditionally set the value of the FINDPARM macro variable.&amp;nbsp; If the value in EXIST is TRUE then FINDPARM is going to be set to the string that starts with a hyphen.&amp;nbsp; &amp;nbsp;Looks like they are perhaps command line options that will be used latter with some Unix command.&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=" language-sas"&gt;%else %do;
  %let findparm= -type f; 
%end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But when the dataset did not exist it just set FINDPARM to that shorter string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That should be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which marks the end of the definition of the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have defined the macro you can then call it using&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%check&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And it will update (and possibly create) the two macro variables based on whether or not the dataset exists.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Read about the scoping of macro variables&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1b76sxg9dbcyrn1l5age5j5nvgw.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1b76sxg9dbcyrn1l5age5j5nvgw.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A macro variable that is in the LOCAL scope of the macro disappears when the macro finishes. The reason to use %GLOBAL is to ensure that the values assigned while teh macro runs are available after the macro has finished running.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that another way to make sure the macro variable's value exists after the macro finishes running is to define the macro variable before calling the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To avoid the error that would occur if the macro variables already existed as LOCAL to some other macro that is calling %CHECK you should only conditionally run the %GLOBAL statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if not %symexist(exists) %then %global exists;
%if not %symexist(findparm) %then %global findparm; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 19:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-this-statement-say-and-does-Global/m-p/848787#M335566</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-09T19:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: What does this statement say and does? Global…..</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-this-statement-say-and-does-Global/m-p/848796#M335570</link>
      <description>Thanks from both for great explanation. &lt;BR /&gt;The only thing I didn’t understand is what -type f. -newer. I know the value of this string is assigned in findparm.&lt;BR /&gt;But what happens If we simply say - type without f and without -newer?&lt;BR /&gt;Respectfully &lt;BR /&gt;Bittenapple</description>
      <pubDate>Fri, 09 Dec 2022 20:14:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-this-statement-say-and-does-Global/m-p/848796#M335570</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-12-09T20:14:07Z</dc:date>
    </item>
    <item>
      <title>Re: What does this statement say and does? Global…..</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-this-statement-say-and-does-Global/m-p/848797#M335571</link>
      <description>Thank you so very much for this explanation. &lt;BR /&gt;Respectfully &lt;BR /&gt;Bittenapple</description>
      <pubDate>Fri, 09 Dec 2022 20:14:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-this-statement-say-and-does-Global/m-p/848797#M335571</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-12-09T20:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: What does this statement say and does? Global…..</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-this-statement-say-and-does-Global/m-p/848810#M335573</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks from both for great explanation. &lt;BR /&gt;The only thing I didn’t understand is what -type f. -newer. I know the value of this string is assigned in findparm.&lt;BR /&gt;But what happens If we simply say - type without f and without -newer?&lt;BR /&gt;Respectfully &lt;BR /&gt;Bittenapple&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;We don't know since the macro variable is not used for anything in the code you shared.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like I said I expect it will be used to generate a Unix command.&amp;nbsp; From the name and the options mentioned I would guess the &lt;A href="https://www.geeksforgeeks.org/find-command-in-linux-with-examples/" target="_self"&gt;find&lt;/A&gt; command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 20:57:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-this-statement-say-and-does-Global/m-p/848810#M335573</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-09T20:57:42Z</dc:date>
    </item>
  </channel>
</rss>

