<?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 to assign missing macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-missing-macro-variable/m-p/103156#M21522</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You probably have trouble in your data step because DIR will output multiple lines of text.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To the specific question of how to set a default value you probably want to set the value BEFORE running the step that will find the value, if it exists.&amp;nbsp; Similar to how you would handle it when using the INTO clause in PROC SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let moddate=0;&lt;/P&gt;&lt;P&gt;data ....&lt;/P&gt;&lt;P&gt; if ... then call symputx('moddate',......);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 23 Oct 2012 16:00:03 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2012-10-23T16:00:03Z</dc:date>
    <item>
      <title>How to assign missing macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-missing-macro-variable/m-p/103153#M21519</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i'm using the below code to check a file create date and later assign that date to a macro variable (moddate). The code works fine when file&amp;nbsp; exists but when there is no file in the declared path then I want moddate to be zero.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let Filenm= c:\xyz.xls;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename finput pipe %unquote(%str(%'dir "&amp;amp;filenm" /t:w /a:-d%'));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;infile finput firstobs = 6;&lt;/P&gt;&lt;P&gt;input moddate ?? :mmddyy8. modtime ?? &amp;amp; time8.;&lt;/P&gt;&lt;P&gt;if moddate ne . then call symput('moddate',moddate);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%put moddate = &amp;amp;moddate.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i tried &lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;if moddate ne&amp;nbsp; . then call symput('moddate',moddate);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;else &lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;call symput('moddate',&lt;/SPAN&gt;0);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;Now, if I add the above else statement the moddate is giving zero even when the file exist. So how do I assign moddate to 0 only when the file doesn't exist.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;Thanks in advance for your help!&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Oct 2012 22:32:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-missing-macro-variable/m-p/103153#M21519</guid>
      <dc:creator>vicky07</dc:creator>
      <dc:date>2012-10-22T22:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign missing macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-missing-macro-variable/m-p/103154#M21520</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There was a post on that today &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://blogs.sas.com/content/sastraining/2012/10/22/macro-programmers-watch-out-for-the-dead-mans-curve/?utm_source=feedburner&amp;amp;utm_medium=email&amp;amp;utm_campaign=Feed%3A+TheSasTrainingPost+%28The+SAS+Training+Post%29" title="http://blogs.sas.com/content/sastraining/2012/10/22/macro-programmers-watch-out-for-the-dead-mans-curve/?utm_source=feedburner&amp;amp;utm_medium=email&amp;amp;utm_campaign=Feed%3A+TheSasTrainingPost+%28The+SAS+Training+Post%29"&gt; Macro programmers: watch out for the Dead Man&amp;amp;#8217;s Curve! - The SAS Training Post&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Oct 2012 22:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-missing-macro-variable/m-p/103154#M21520</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2012-10-22T22:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign missing macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-missing-macro-variable/m-p/103155#M21521</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First, on a side note, you would be better off switching from SYMPUT to SYMPUTX.&amp;nbsp; That would avoid placing leading blanks on &amp;amp;MODDATE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It looks like you have removed the messages that would give you a clue as to the source of the problem.&amp;nbsp; Most likely, the raw data you are piping in is not in the form that you expect (such as MMDDYY8.).&amp;nbsp; You can add this statement to the end of the DATA step to find out: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;list;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It will list the data line on the .log file, so you can see what you are attempting to read.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The most likely explanation is that the date is coming in using some other format that cannot be interpreted as a date in MMDDYY8. form.&amp;nbsp; So the INPUT statement is generating a missing value, but the ?? suppresses any message about invalid data.&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Oct 2012 15:19:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-missing-macro-variable/m-p/103155#M21521</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-10-23T15:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign missing macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-missing-macro-variable/m-p/103156#M21522</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You probably have trouble in your data step because DIR will output multiple lines of text.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To the specific question of how to set a default value you probably want to set the value BEFORE running the step that will find the value, if it exists.&amp;nbsp; Similar to how you would handle it when using the INTO clause in PROC SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let moddate=0;&lt;/P&gt;&lt;P&gt;data ....&lt;/P&gt;&lt;P&gt; if ... then call symputx('moddate',......);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Oct 2012 16:00:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-missing-macro-variable/m-p/103156#M21522</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-10-23T16:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign missing macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-missing-macro-variable/m-p/103157#M21523</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I might suggest using the external file information functions instead of parsing output from DIR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From online help the following would return the data elements available. Then you could use this to find the specific data elements of interest. Also there are FILEEXIST and FEXIST that let you determine if the file named exists.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A name="a000226153"&gt;&lt;/A&gt;data info;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length infoname infoval $60;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop rc fid infonum i close;&lt;/P&gt;&lt;P&gt;&amp;nbsp; rc=filename('abc','c:\xyz.xls');&lt;/P&gt;&lt;P&gt;&amp;nbsp; fid=fopen('abc');&lt;/P&gt;&lt;P&gt;&amp;nbsp; infonum=foptnum(fid);&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to infonum;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infoname=foptname(fid,i);&lt;/P&gt;&lt;P&gt;&amp;nbsp; infoval=finfo(fid,infoname);&lt;/P&gt;&lt;P&gt;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; close=fclose(fid);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Oct 2012 17:50:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-missing-macro-variable/m-p/103157#M21523</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2012-10-23T17:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign missing macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-missing-macro-variable/m-p/103158#M21524</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all for your help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Oct 2012 22:11:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-missing-macro-variable/m-p/103158#M21524</guid>
      <dc:creator>vicky07</dc:creator>
      <dc:date>2012-10-23T22:11:06Z</dc:date>
    </item>
  </channel>
</rss>

