<?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: How use EXIST function. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-use-EXIST-function/m-p/516674#M139579</link>
    <description>&lt;P&gt;Or you could just simplfy your code to:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  if exist("&amp;amp;ds1_in.") then do;
    call symputx("date1","20171231","g");
    call symputx("date2","20180131","g");
  end;
  else do;
    call symputx("date1","20180131","g");
    call symputx("date2","20180228","g");   
  end;
run;&lt;/PRE&gt;
&lt;P&gt;However I strongly advise against creating global macro variables in a macro.&amp;nbsp; This can lead to some very difficult debugging down the line.&amp;nbsp; Global macro variables affect the whole system.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, why would you need to create macro variables for these?&amp;nbsp; You obviously want the end of the current month as lower, and end of the next month as upper, based on the existence of some file?&amp;nbsp; Effectively all you are doing is hardcoding in the formula:&lt;/P&gt;
&lt;PRE&gt;intnx('month',&amp;lt;date&amp;gt;,0,"e") ... intnx('month',&amp;lt;date&amp;gt;,1,"e")&lt;/PRE&gt;
&lt;P&gt;Which is really just a waste of code space, use the formula and ditch all the messy useless macro code.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Nov 2018 14:17:20 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-11-28T14:17:20Z</dc:date>
    <item>
      <title>How use EXIST function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-use-EXIST-function/m-p/516655#M139566</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to use &lt;STRONG&gt;exist&lt;/STRONG&gt; &lt;STRONG&gt;function,&amp;nbsp;&lt;/STRONG&gt;but it seems doesn't work as I would like.&lt;/P&gt;&lt;P&gt;I want assign macrovalue different value conditionally if a dataset exist or not.&lt;/P&gt;&lt;P&gt;I provide an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/***** TEST DATA ******/

DATA test_1;
	x = 2;
run;
DATA test_2;
	x = 2;
run;

/* assing different value to macrovalue date1 and date2 if ds test_1 and 
   test_2 exist or not */

%let ds1_in = work.test_1;
%let ds2_in = work.test_2;

%macro exist;
	%global date1 date2;
		  %if %sysfunc(exist(&amp;amp;ds1_in.) %then %do;
				%let date1 = 20171231;
				%let date2 = 20180131;
		   %end;
	%else %if %sysfunc(exist(&amp;amp;ds2_in.) %then %do;
			        %let date1 = 20180131;
				%let date2 = 20180228;
	%end;
	%else %put "error";
%mend;
%exist;

%put date1 = &amp;amp;date1.;
%put date2 = &amp;amp;date2.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I surly make some errors because when I submit macro program the follow massage is written in the log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Remote submit to RHOST commencing.
47   %macro exist;
48       %global date1 date2;
49             %if %sysfunc(exist(&amp;amp;ds1_in.) %then %do;
ERROR: Macro keyword DO appears as text.
ERROR: A dummy macro will be compiled.
50                   %let date1 = 20171231;
ERROR: Macro keyword LET appears as text.
51                   %let date2 = 20180131;
ERROR: Macro keyword LET appears as text.
52             %end;
ERROR: Macro keyword END appears as text.
53       %else %if %sysfunc(exist(&amp;amp;ds2_in.) %then %do;
ERROR: There is no matching %IF statement for the %ELSE.
ERROR: Macro keyword IF appears as text.
54                   %let date1 = 20180131;
ERROR: Macro keyword LET appears as text.
55                   %let date2 = 20180228;
ERROR: Macro keyword LET appears as text.
56       %end;
ERROR: Macro keyword END appears as text.
57       %else %put "error";
ERROR: There is no matching %IF statement for the %ELSE.
ERROR: Macro keyword PUT appears as text.
58   %mend;
ERROR: Macro keyword MEND appears as text.
59   %exist;
60   %put date1 = &amp;amp;date1.;
ERROR: Macro keyword PUT appears as text.
61   %put date2 = &amp;amp;date2.;
ERROR: Macro keyword PUT appears as text.
NOTE: Remote submit to RHOST complete.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can you explain me why?&lt;/P&gt;&lt;P&gt;Mybe is better to use exist function in a datestep than in a macroprogram?&lt;/P&gt;&lt;P&gt;Thanks for your help and time...I have spent several days on this but I can't fix it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 13:28:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-use-EXIST-function/m-p/516655#M139566</guid>
      <dc:creator>Ccasagran737</dc:creator>
      <dc:date>2018-11-28T13:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: How use EXIST function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-use-EXIST-function/m-p/516659#M139569</link>
      <description>&lt;P&gt;How about having matching left and right parentheses? Such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro exist;
	%global date1 date2;
		  %if %sysfunc(exist(&amp;amp;ds1_in.)) %then %do;
				%let date1 = 20171231;
				%let date2 = 20180131;
		   %end;
	%else %if %sysfunc(exist(&amp;amp;ds2_in.)) %then %do;
			        %let date1 = 20180131;
				%let date2 = 20180228;
	%end;
	%else %put "error";
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Nov 2018 13:35:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-use-EXIST-function/m-p/516659#M139569</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-11-28T13:35:38Z</dc:date>
    </item>
    <item>
      <title>Re: How use EXIST function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-use-EXIST-function/m-p/516661#M139570</link>
      <description>&lt;P&gt;Looks like you are missing a parenthesis .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysfunc(exist(&amp;amp;ds1_in.) &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 13:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-use-EXIST-function/m-p/516661#M139570</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2018-11-28T13:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: How use EXIST function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-use-EXIST-function/m-p/516674#M139579</link>
      <description>&lt;P&gt;Or you could just simplfy your code to:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  if exist("&amp;amp;ds1_in.") then do;
    call symputx("date1","20171231","g");
    call symputx("date2","20180131","g");
  end;
  else do;
    call symputx("date1","20180131","g");
    call symputx("date2","20180228","g");   
  end;
run;&lt;/PRE&gt;
&lt;P&gt;However I strongly advise against creating global macro variables in a macro.&amp;nbsp; This can lead to some very difficult debugging down the line.&amp;nbsp; Global macro variables affect the whole system.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, why would you need to create macro variables for these?&amp;nbsp; You obviously want the end of the current month as lower, and end of the next month as upper, based on the existence of some file?&amp;nbsp; Effectively all you are doing is hardcoding in the formula:&lt;/P&gt;
&lt;PRE&gt;intnx('month',&amp;lt;date&amp;gt;,0,"e") ... intnx('month',&amp;lt;date&amp;gt;,1,"e")&lt;/PRE&gt;
&lt;P&gt;Which is really just a waste of code space, use the formula and ditch all the messy useless macro code.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 14:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-use-EXIST-function/m-p/516674#M139579</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-28T14:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: How use EXIST function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-use-EXIST-function/m-p/516895#M139647</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have followed your advice...do you mean something like this? I have tried and it seems work.&lt;/P&gt;&lt;P&gt;Thank for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  		if exist("&amp;amp;ds2_in.") then do;
  			dt_rep_1 = put("31OCT2018"d, date9.);
  			dt_rep_2 = put(intnx("month","31OCT2018"d,-1,"e"), date9.);
  		end;
  	else if exist("&amp;amp;ds1_in.") then do;
  			dt_rep_1 = put(intnx("month","31OCT2018"d,-1,"e"), date9.);
  			dt_rep_2 = put(intnx("month","31OCT2018"d,-2,"e"), date9.);
  	end;
    call symputx("date1",dt_rep_1,"g");
    call symputx("date2",dt_rep_2,"g");
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 22:47:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-use-EXIST-function/m-p/516895#M139647</guid>
      <dc:creator>Ccasagran737</dc:creator>
      <dc:date>2018-11-28T22:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: How use EXIST function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-use-EXIST-function/m-p/516966#M139667</link>
      <description>&lt;P&gt;No.&amp;nbsp; What I mean is do not create the macro variables at all.&amp;nbsp; In your code, where you would have used the macro variables, you use the simply intnx() formula provided.&amp;nbsp; This avoids creating macro code at all.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 09:22:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-use-EXIST-function/m-p/516966#M139667</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-29T09:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: How use EXIST function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-use-EXIST-function/m-p/516974#M139670</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The name of macro is same of function&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA test_1;
	x = 2;
run;
DATA test_2;
	x = 2;
run;

/* assing different value to macrovalue date1 and date2 if ds test_1 and 
   test_2 exist or not */

%let ds1_in = work.test_1;
%let ds2_in = work.test_2;

%macro tt();
	%global date1 date2;
		  %if %sysfunc(exist(&amp;amp;ds1_in.)) %then %do;
				%let date1 = 20171231;
				%let date2 = 20180131;
		   %end;
	%else %if %sysfunc(exist(&amp;amp;ds2_in.)) %then %do;
			        %let date1 = 20180131;
				%let date2 = 20180228;
	%end;
	%else %put "error";
%mend;
%tt;

%put date1 = &amp;amp;date1.;
%put date2 = &amp;amp;date2.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Nov 2018 09:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-use-EXIST-function/m-p/516974#M139670</guid>
      <dc:creator>mansour_ib_sas</dc:creator>
      <dc:date>2018-11-29T09:48:42Z</dc:date>
    </item>
  </channel>
</rss>

