<?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: IF/THEN/ELSE Proc Import Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/623940#M183735</link>
    <description>&lt;P&gt;The next step in debugging is to actually look at the code produced by this macro and see if the values of the macro variables are what you expect. So again, I ask to see the log.&lt;/P&gt;</description>
    <pubDate>Tue, 11 Feb 2020 18:55:39 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-02-11T18:55:39Z</dc:date>
    <item>
      <title>IF/THEN/ELSE Proc Import Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/623927#M183730</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I have been trying to create a macro to avoid my proc import from&amp;nbsp;erroring out&amp;nbsp;if the file does not exist. It is based upon the date that the user inputs prior to running the file. Here is a bit of code for reference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; &lt;STRONG&gt;&lt;I&gt;y4import&lt;/I&gt;&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;%If&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; floor(&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New"&gt;end_date.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;/&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;100&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;) &amp;gt;= &amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New"&gt;Year4.&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;PROC IMPORT OUT = WORK.Rates_&amp;amp;YEAR4._H1 DATAFILE= YR4H2 DBMS=xlsx REPLACE;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT face="Courier New"&gt;SHEET=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"SAS Prep"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;GETNAMES=YES;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;RUN;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; ;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;%else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; y4import;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;%&lt;STRONG&gt;&lt;I&gt;y4import&lt;/I&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Year4 and End_date are both variables that are set previously. End_date is manually put in by the user and Year4 is a macro that takes the year from the beg_date set by the user and steps it forward 3 years. End_date is an integer in YYYYMM format, thus why the floor function is used. When I run the code above, nothing happens, even though I have manipulated the variables to ensure that the %If statement is true.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To summarize, I am trying to achieve that if the end_date for data to be imported is not equal to or greater than year4, then don't import the file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any insight on this, or if this is even possible&amp;nbsp;would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 18:22:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/623927#M183730</guid>
      <dc:creator>ImASasMan</dc:creator>
      <dc:date>2020-02-11T18:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Proc Import Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/623928#M183731</link>
      <description>&lt;P&gt;Are there error messages in the log? Can you show them to us?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please re-run the program with this as the first line&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen mlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then show us the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;In particular, this won't work&lt;/P&gt;
&lt;PRE&gt;%If floor(&amp;amp;end_date./100) &amp;gt;= &amp;amp;Year4. %then %do;&lt;/PRE&gt;
&lt;P&gt;because floor will not work with %IF. You could use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%If %sysfunc(floor(&amp;amp;end_date./100)) &amp;gt;= &amp;amp;Year4. %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because FLOOR isn't recognized by&amp;nbsp; the macro processor unless it is inside %SYSFUNC&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Whether there are other errors, I don't know. The log ought to make clear what the problems are.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 18:29:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/623928#M183731</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-11T18:29:08Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Proc Import Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/623936#M183734</link>
      <description>&lt;P&gt;Prior to adding the %sysfunc and options lines, there were no errors or warnings to report. After adding them, nothing occurred, and there were still no errors or warnings to report.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 18:52:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/623936#M183734</guid>
      <dc:creator>ImASasMan</dc:creator>
      <dc:date>2020-02-11T18:52:56Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Proc Import Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/623940#M183735</link>
      <description>&lt;P&gt;The next step in debugging is to actually look at the code produced by this macro and see if the values of the macro variables are what you expect. So again, I ask to see the log.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 18:55:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/623940#M183735</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-11T18:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Proc Import Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/623951#M183736</link>
      <description>&lt;P&gt;You macro is referencing two macro variables , END_DATE and YEAR4, that are NOT defined as inputs to the macro.&amp;nbsp; Where are those macro variables defined? What values do they have?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the test that you want to perform?&amp;nbsp; Right now you are testing if the lowercase letter f is larger than the first character in the macro variable YEAR4.&amp;nbsp; If YEAR4 has something like 2020 then the digit 2 is always smaller than any letter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does you macro even compile?&amp;nbsp; You have a %END without any corresponding %DO.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you didn't define any input parameters to the macro you might want to add a semi-colon after the macro call to make sure that SAS knows you are done typing the name of the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 19:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/623951#M183736</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-11T19:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Proc Import Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/623966#M183737</link>
      <description>&lt;P&gt;It seems like you're asking two questions here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. What is wrong with my current code?&lt;/P&gt;
&lt;P&gt;2. How to check if a file exists and call this macro conditionally.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The answer to #2 is here, basically use the FILEEXIST() function and then add an %IF/%THEN based on that logic. In this example it deletes the file using FDELETE but you'll want to run your IMPORT instead.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n108rtvqj4uf7tn13tact6ggb6uf.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n108rtvqj4uf7tn13tact6ggb6uf.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding #1, as others have indicated you'll have to post the log with the debugging options for us to tell what's wrong. We can't see the code you actually submit or what the macro variables resolve to, so we can only comment on what you've posted which doesn't indicate where the error may be.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good Luck.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 19:23:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/623966#M183737</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-11T19:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Proc Import Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/623967#M183738</link>
      <description>&lt;P&gt;These macros are defined earlier in the code and are referenced throughout the sheet in various file paths, names, etc. Do they need to be referenced directly in the macro?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;End_Date is defined as 202001 and Year4 is defined as 2020.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to test that the first 4 digits of end_date are equal to or greater than the value in Year4.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 19:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/623967#M183738</guid>
      <dc:creator>ImASasMan</dc:creator>
      <dc:date>2020-02-11T19:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Proc Import Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/623975#M183739</link>
      <description>&lt;P&gt;Untested.&lt;/P&gt;
&lt;P&gt;FEXIST() to check for file exist and using %SYSFUNC() to wrap functions in a macro.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FYI - I would highly recommend redesigning this a bit to use parameters rather than assume a macro variable exists. Its a helpful design feature to ensure your code is using the correct parameters and makes your process more efficient in the long run. I'll assume you're actually incorporating this into another program, not calling it in the fashion you are here though.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let end_date = 202001;
%let year4 = 2020;

%macro y4import;

%If %sysfunc(floor(&amp;amp;end_date./100)) &amp;gt;= &amp;amp;Year4. and %sysfunc(fexist(yr4h2)) %then %do;

 

PROC IMPORT OUT = WORK.Rates_&amp;amp;YEAR4._H1 DATAFILE= YR4H2 DBMS=xlsx REPLACE;

SHEET="SAS Prep";

 

GETNAMES=YES;

RUN;

%end ;



%mend y4import;

 

%y4import&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Feb 2020 19:36:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/623975#M183739</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-11T19:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Proc Import Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/624031#M183757</link>
      <description>&lt;P&gt;Are any of these XLSX files supposed to have similar structure and content? This means the same number of variables, with the same names and each variable having the same properties such as type (numeric or character) length and possibly date values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so I would suggest manually importing two of them and then run proc contents on those two resulting data sets. See if the variables, especially character, have the same properties.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not then Proc Import for many files is going to lead to many steps to "fix" them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I might suggest using PCFiLES and reading them into a standard structured data set.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 21:36:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/624031#M183757</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-02-11T21:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Proc Import Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/624041#M183760</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/311672"&gt;@ImASasMan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;These macros are defined earlier in the code and are referenced throughout the sheet in various file paths, names, etc. Do they need to be referenced directly in the macro?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;End_Date is defined as 202001 and Year4 is defined as 2020.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to test that the first 4 digits of end_date are equal to or greater than the value in Year4.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So you want to compare the first 4 characters of END_DATE to YEAR4?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if "%substr(&amp;amp;end_date,1,4)"="&amp;amp;year4" %then ...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Feb 2020 22:20:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/624041#M183760</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-11T22:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Proc Import Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/624158#M183811</link>
      <description>&lt;P&gt;Thank you everyone for the replies. The reason I was having such an issue with this was because I needed to restart my SAS. The state it was in when I posted this was not erroring out and giving me proper insight. The simple solution was to add the %sysfunc in front of floor and add a %do in the %else statement. Here is what I ended up using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &lt;STRONG&gt;&lt;I&gt;y4H1import&lt;/I&gt;&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; MONTH = (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%EVAL&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;END_DATE. - &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%EVAL&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;YEAR4.*100)));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%If&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%SYSFUNC&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(floor(&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;end_date.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;/&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;100&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;)) &amp;gt;= &amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;Year4.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; AND &amp;amp;MONTH &amp;lt; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;7&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC IMPORT OUT = WORK.Rates_&amp;amp;YEAR4._H1 DATAFILE= YR4H1 DBMS=xlsx REPLACE;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;SHEET=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"SAS Prep"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;GETNAMES=YES;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%ELSE&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%DO&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%PUT&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; THE FILE DOES NOT EXIST;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%END&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; y4H1import;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;y4H1import&lt;/I&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2020 13:06:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/624158#M183811</guid>
      <dc:creator>ImASasMan</dc:creator>
      <dc:date>2020-02-12T13:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Proc Import Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/624171#M183822</link>
      <description>&lt;P&gt;There is no need to nest the %EVAL() function calls. Once you are asking the macro processor to evaluate an integer arithmetic expression it can do the whole expression.&amp;nbsp; Do you really want the MONTH macro variable to have the parentheses in it?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET MONTH = %EVAL(&amp;amp;END_DATE. - (&amp;amp;YEAR4.*100));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But since the string is in YYYYMM format to get the MM part out you can&amp;nbsp; just use %SUBSTR() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let month=%substr(&amp;amp;end_date,5)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You seem to have changed the logic of your test by introducing this test of the month value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you appear to be testing whether the YYYYMM string in END_DATE is for any year that is equal to or larger than the YYYY string in YEAR4 but also within the first half of the year.&amp;nbsp; So if YEAR4 is 2019 then values like 201903, 202005, 203006 will be valid.&amp;nbsp; But values like 201908, 201801, 202012 are not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or did you just want to test if it is in the first half of the year that YEAR4 represents?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%If &amp;amp;year4.01 &amp;lt;= &amp;amp;end_date &amp;lt;= &amp;amp;year4.06 %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2020 13:59:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/624171#M183822</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-12T13:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Proc Import Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/624222#M183853</link>
      <description>Given your initial question:&lt;BR /&gt;"So I have been trying to create a macro to avoid my proc import from erroring out if the file does not exist"&lt;BR /&gt;&lt;BR /&gt;Your answer above does not do what you initially asked. It checks the month/date but not if a file exists. If that's what you needed, great.</description>
      <pubDate>Wed, 12 Feb 2020 15:52:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/624222#M183853</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-12T15:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Proc Import Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/624227#M183857</link>
      <description>&lt;P&gt;Thank you guys for the replies. As I'm sure you can tell, I am new to SAS, only been using it for about a month now. After posting again this morning and getting your comments back I found that my logic was in fact flawed and should not based upon the month and year values, but rather if the file itself exists. I proceeded to use the FILEEXIST function as was suggested yesterday. The code is as follows and ran properly without erroring out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &lt;STRONG&gt;&lt;I&gt;check1&lt;/I&gt;&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%if&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(fileexist(&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;FILE_CHECK1.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)) ge &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;PROC IMPORT OUT = WORK.Rates_&amp;amp;YEAR4._H1 DATAFILE= YR4H1 DBMS=xlsx REPLACE;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;SHEET=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"SAS Prep"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;GETNAMES=YES;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;***************************&lt;/P&gt;&lt;P&gt;The file &amp;amp;FILE_CHECK2. does not exist&lt;/P&gt;&lt;P&gt;****************************;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; check1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;check1&lt;/I&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One mistake that I made along the way is that I tried to use the FILENAME that I had established for the import statement as a callable variable, which obviously is incorrect. I had to establish a new variable that added .xlsx onto the file path. Any other suggestions for improvements are greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2020 15:59:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Proc-Import-Macro/m-p/624227#M183857</guid>
      <dc:creator>ImASasMan</dc:creator>
      <dc:date>2020-02-12T15:59:45Z</dc:date>
    </item>
  </channel>
</rss>

