<?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: Missing Value in variable as macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136584#M27645</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;the following procedure will replace all&amp;nbsp; numeric variable values with zero.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; proc stdize data= have reponly MISSING=0 out=want;&lt;/P&gt;&lt;P&gt; var _numeric_;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 13 Nov 2013 04:55:54 GMT</pubDate>
    <dc:creator>Mit</dc:creator>
    <dc:date>2013-11-13T04:55:54Z</dc:date>
    <item>
      <title>Missing Value in variable as macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136577#M27638</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I have a dataset Have which may or may not contain data. I need to basically create one macro variable which will have value zero if its missing. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data have ;&lt;/P&gt;&lt;P&gt;Input var1 var2;&lt;/P&gt;&lt;P&gt;Cards;&lt;/P&gt;&lt;P&gt;1 a&lt;/P&gt;&lt;P&gt;. B&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My macro is&lt;/P&gt;&lt;P&gt;%macro m1;&lt;/P&gt;&lt;P&gt;Proc sql;&lt;/P&gt;&lt;P&gt;Select var1 into :var1 where var2='B'&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;Quit;&lt;/P&gt;&lt;P&gt;%let var1_new=%eval(&amp;amp;var1 +1);&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%m1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So basically I want var1_new to be resolved to 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Has anyone faced similar problem.&amp;nbsp; Any ideas are welcome&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Nov 2013 17:34:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136577#M27638</guid>
      <dc:creator>yashpande</dc:creator>
      <dc:date>2013-11-08T17:34:27Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Value in variable as macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136578#M27639</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is your question:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Has anyone faced similar problem? (that's what you said, that's the only question I can find in your post, in which case I think the answer is YES)&lt;/LI&gt;&lt;LI&gt;How to achieve this for this exact sitaution where you are testing for var2='B'? (in which case I think the answer is that you just did it)&lt;/LI&gt;&lt;LI&gt;How to achieve this in general? (in which case I think you need to be more specific about what general situations you want to find and what you mean by "zero if its missing")&lt;/LI&gt;&lt;/OL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Nov 2013 17:43:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136578#M27639</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2013-11-08T17:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Value in variable as macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136579#M27640</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use the sum function instead, once you fix the code before. 2 additional bugs above...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Input - didn't identify character variable&lt;/P&gt;&lt;P&gt;2. Proc SQL - no from table&lt;/P&gt;&lt;P&gt;3. Use %sysfunc(sum(&amp;amp;var1, 1)) instead of eval&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data have ;&lt;/P&gt;&lt;P&gt;Input var1 var2 $;&lt;/P&gt;&lt;P&gt;Cards;&lt;/P&gt;&lt;P&gt;1 a&lt;/P&gt;&lt;P&gt;. B&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc sql;&lt;/P&gt;&lt;P&gt;Select var1 into :var1 &lt;/P&gt;&lt;P&gt;from have&lt;/P&gt;&lt;P&gt;where var2='B';&lt;/P&gt;&lt;P&gt;Quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let var1_new=%sysfunc(sum(&amp;amp;var1, 1));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;var1_new.;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Nov 2013 17:45:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136579#M27640</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-11-08T17:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Value in variable as macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136580#M27641</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P&gt;Fareeza Khurshed wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Use the sum function instead, once you fix the code before. 2 additional bugs above...&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;1. Input - didn't identify character variable&lt;/P&gt;
&lt;P&gt;2. Proc SQL - no from table&lt;/P&gt;
&lt;P&gt;3. Use %sysfunc(sum(&amp;amp;var1, 1)) instead of eval&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Data have ;&lt;/P&gt;
&lt;P&gt;Input var1 var2 $;&lt;/P&gt;
&lt;P&gt;Cards;&lt;/P&gt;
&lt;P&gt;1 a&lt;/P&gt;
&lt;P&gt;. B&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;Run;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Proc sql;&lt;/P&gt;
&lt;P&gt;Select var1 into :var1&lt;/P&gt;
&lt;P&gt;from have&lt;/P&gt;
&lt;P&gt;where var2='B';&lt;/P&gt;
&lt;P&gt;Quit;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;%let var1_new=%sysfunc(sum(&amp;amp;var1, 1));&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;var1_new.;&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;How about this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data have ;&lt;/P&gt;&lt;P&gt;Input var1 var2 $;&lt;/P&gt;&lt;P&gt;if var2='B' then call symputx('var1_new',not missing(var1));&lt;/P&gt;&lt;P&gt;Cards;&lt;/P&gt;&lt;P&gt;1 a&lt;/P&gt;&lt;P&gt;. B&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Nov 2013 17:50:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136580#M27641</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2013-11-08T17:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Value in variable as macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136581#M27642</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Page ,I want to select the latest value.&amp;nbsp; If its missing then I should get zero.&amp;nbsp; Will above call symput work in such case ? Let me try it and get back to you. As for sql and sum concerned I think sum won't work because say if I have 2 non missing values then it will sym up and result will be wrong.&amp;nbsp; I want latest value.&amp;nbsp; If there is no latest then it should be treated as zero. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Will coalesce work in such cases ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Nov 2013 06:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136581#M27642</guid>
      <dc:creator>yashpande</dc:creator>
      <dc:date>2013-11-09T06:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Value in variable as macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136582#M27643</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Let's assume that the problem is to find the LAST value for a numeric variable when using a WHERE clause.&amp;nbsp; Further, if the last value is missing or if there are no observations in the input dataset then return 0 as the result.&lt;/P&gt;&lt;P&gt;In this example I use &lt;STRONG&gt;WANT&lt;/STRONG&gt; as the input dataset, &lt;STRONG&gt;VAR1&lt;/STRONG&gt; as the name of the numeric variable and &lt;STRONG&gt;LAST_VAR1&lt;/STRONG&gt; as the name of the macro variable to contain the result.&amp;nbsp; For my WHERE condition I will use &lt;STRONG&gt;VAR2='B'&lt;/STRONG&gt; .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let last_var1=0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set have end=eof ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; where var2='B';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if eof then call symputx('last_var1',sum(0,var1));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;This will NOT handle the case where the input dataset does not exist.&amp;nbsp; In that case you will get an ERROR from SAS for attempting to reference a dataset that doesn't exist.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Nov 2013 22:03:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136582#M27643</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-11-09T22:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Value in variable as macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136583#M27644</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P&gt;&lt;BR id="mce_1" /&gt;Hi Page ,I want to select the latest value.&amp;nbsp; If its missing then I should get zero.&amp;nbsp; Will above call symput work in such case ? Let me try it and get back to you. As for sql and sum concerned I think sum won't work because say if I have 2 non missing values then it will sym up and result will be wrong.&amp;nbsp; I want latest value.&amp;nbsp; If there is no latest then it should be treated as zero.&lt;/P&gt;




&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Realizing that it is possible that English is not your native language, do you mean "last value" or "latest value"? "Last value" makes sense assuming the data is sorted in the proper order, "latest value" does not make sense to me here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regarding this criterion of using the "Last" or "Latest" value, it sure would have been nice if you had stated this criterion right at the start instead of letting us guess you wanted var2='B'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, assuming the data is sorted properly by var2, this code would work&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data have ;&lt;BR /&gt;Input var1 var2 $;&lt;BR /&gt;Cards;&lt;/P&gt;&lt;P&gt;1 a&lt;/P&gt;&lt;P&gt;. B&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt; set have end=eof;&lt;BR /&gt; if eof then call symputx('var1_new',not missing(var1));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;humor&amp;gt; where data _null_; is an actual SAS command and does not refer to the individual in this forum who uses the name data _null_; &amp;lt;/humor&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Nov 2013 14:20:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136583#M27644</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2013-11-11T14:20:26Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Value in variable as macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136584#M27645</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;the following procedure will replace all&amp;nbsp; numeric variable values with zero.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; proc stdize data= have reponly MISSING=0 out=want;&lt;/P&gt;&lt;P&gt; var _numeric_;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Nov 2013 04:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136584#M27645</guid>
      <dc:creator>Mit</dc:creator>
      <dc:date>2013-11-13T04:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Value in variable as macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136585#M27646</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I mean all non missing&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the following procedure will &lt;STRONG style="text-decoration: underline;"&gt;replace all&amp;nbsp; missing numeric variable values with zero&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; proc stdize data= have reponly MISSING=0 out=want;&lt;/P&gt;&lt;P&gt; var _numeric_;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Nov 2013 01:58:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-Value-in-variable-as-macro/m-p/136585#M27646</guid>
      <dc:creator>Mit</dc:creator>
      <dc:date>2013-11-18T01:58:31Z</dc:date>
    </item>
  </channel>
</rss>

