<?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: scan function with if stetement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/scan-function-with-if-stetement/m-p/463454#M118076</link>
    <description>&lt;P&gt;When you use a DATE value with scan you get missing when scanning for the second value.&lt;/P&gt;
&lt;PRE&gt;data _null_;
   complete_date= today();
   format complete_date ddmmyy10.;
   datathismonth = scan(complete_date,2,"/");
   put "data this month is: " datathismonth;
   scanresult = scan(complete_date,1);
   put scanresult=;
run;&lt;/PRE&gt;
&lt;P&gt;You have to specifically either use the Put(datevalue,ddmmyy10) in the scan function OR&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;much better idea, use the proper function such as MONTH(complete_date).&lt;/P&gt;</description>
    <pubDate>Fri, 18 May 2018 22:29:27 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-05-18T22:29:27Z</dc:date>
    <item>
      <title>scan function with if stetement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-function-with-if-stetement/m-p/463439#M118071</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use scan function with if statement but I guess I'm doing a mistake that prevents the variable count to count the observation that has this month. I'm not getting any error in the log but I'm not getting what I want&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is my code&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let todaysdate= %sysfunc(today(), DDMMYY10.);&lt;BR /&gt;&lt;BR /&gt;%let thismonth=%scan(&amp;amp;todaysdate,2,"/");&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;PRE&gt;data Asterias2; &lt;BR /&gt;set Asterias1; &lt;BR /&gt; &lt;BR /&gt;format complete_date ddmmyy10.; &lt;BR /&gt;if scan(complete_date,2,"/")=&amp;amp;thismonth then  count=1; &lt;BR /&gt;run;    &lt;/PRE&gt;&lt;P&gt;this is a sample of my data&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Obs&lt;/TD&gt;&lt;TD&gt;complete_date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;29/05/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;29/05/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;10/6/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2/6/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;10/6/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;10/6/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;10/6/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;10/6/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;2/7/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;2/7/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;6/7/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;3/7/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;18/11/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;18/11/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;18/11/2015&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 20:32:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-function-with-if-stetement/m-p/463439#M118071</guid>
      <dc:creator>mona4u</dc:creator>
      <dc:date>2018-05-18T20:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: scan function with if stetement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-function-with-if-stetement/m-p/463441#M118072</link>
      <description>&lt;P&gt;are you missing quotes around macro reference like?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Asterias2; 
set Asterias1; 
 
format complete_date ddmmyy10.; 
if scan(complete_date,2,"/")="&amp;amp;thismonth" then  count=1; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 May 2018 20:35:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-function-with-if-stetement/m-p/463441#M118072</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-18T20:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: scan function with if stetement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-function-with-if-stetement/m-p/463443#M118073</link>
      <description>&lt;P&gt;Post the log of the data step. I bet there's a NOTE about a type conversion.&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 20:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-function-with-if-stetement/m-p/463443#M118073</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-18T20:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: scan function with if stetement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-function-with-if-stetement/m-p/463450#M118075</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;scan&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;complete_date&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"/"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Complete_date is a&amp;nbsp;SAS date, with a date format, it cannot be used with SCAN and it looks like you're trying to see if the months are the same between the two? complete_date is a number, such as 23554, so I'm not even sure what would get returned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, I would use the MONTH() function to extract the month instead.&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 todaysdate= %sysfunc(today());

%let thismonth = %sysfunc(month(&amp;amp;todaysdate.));

data Asterias2; 
set Asterias1; 
 
format complete_date ddmmyy10.; 
if month(complete_date) = &amp;amp;thismonth. then  count=1; 
run;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you don't need macro variables at all for this. You could use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if month(complete_date) = month(today()) then count=1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 May 2018 21:32:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-function-with-if-stetement/m-p/463450#M118075</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-05-18T21:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: scan function with if stetement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-function-with-if-stetement/m-p/463454#M118076</link>
      <description>&lt;P&gt;When you use a DATE value with scan you get missing when scanning for the second value.&lt;/P&gt;
&lt;PRE&gt;data _null_;
   complete_date= today();
   format complete_date ddmmyy10.;
   datathismonth = scan(complete_date,2,"/");
   put "data this month is: " datathismonth;
   scanresult = scan(complete_date,1);
   put scanresult=;
run;&lt;/PRE&gt;
&lt;P&gt;You have to specifically either use the Put(datevalue,ddmmyy10) in the scan function OR&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;much better idea, use the proper function such as MONTH(complete_date).&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 22:29:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-function-with-if-stetement/m-p/463454#M118076</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-18T22:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: scan function with if stetement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-function-with-if-stetement/m-p/463785#M118207</link>
      <description>&lt;P&gt;It didn't work with me&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 May 2018 14:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-function-with-if-stetement/m-p/463785#M118207</guid>
      <dc:creator>mona4u</dc:creator>
      <dc:date>2018-05-21T14:29:35Z</dc:date>
    </item>
  </channel>
</rss>

