<?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: The subject of date format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385214#M92119</link>
    <description>&lt;P&gt;Sure, I understand that my problem is not the matter of date format, and I use the code to get the result. But there are too many duplicate observations producted by the rule of proc sql. &amp;nbsp;I only have variables cusip and yymm_ &amp;nbsp;which have some connections . I will be very appreciated if any suggestion. Thanks&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;a.yymm_a&amp;lt;= b.yymm_e&amp;lt;= intnx('month',a.yymm_a,12,'same');&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 03 Aug 2017 09:01:30 GMT</pubDate>
    <dc:creator>lixuan</dc:creator>
    <dc:date>2017-08-03T09:01:30Z</dc:date>
    <item>
      <title>The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385109#M92078</link>
      <description>&lt;P&gt;Hi, I have problem with date format. Here is my dataset&amp;nbsp;and my code. I dont think I made any mistake, and I cant find the cause. Pls help me , thanks.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.ONE;
  infile datalines dsd truncover;
  input CUSIP:$8. g:32. yymm_a:YYMMN6.;
  format yymm_a YYMMN6.;
  label CUSIP="CUSIP/SEDOL" g="g";
datalines4;
00036020,22.25,199801
00036020,17,199801
00036020,12,199801
00036020,15,199801
00036020,17,199801
00036020,15,199801
00036020,17,199801
00036020,12,199801
00036020,15,199801
00036110,19.6,199705
00036110,19.6,199810
00036110,11,199705
00036110,11,199705
00036110,16.75,199810
00036110,11,199705
00036110,16.8,199705
00036110,16.8,199810
00036110,16.6,200009
00036110,16.6,199810
00036110,15,200009
;;;;
data WORK.TWO;
  infile datalines dsd truncover;
  input CUSIP:$8. g:32. yymm_e:YYMMN6.;
  format yymm_e YYMMN6.;
  label CUSIP="CUSIP/SEDOL" g="g";
datalines4;
00036020,25,199201
00036020,25,199201
00036020,25,199201
00036020,25,199201
00036110,16.75,199706
00036110,16.6,199706
00036110,15,199706
00036110,15,199810
00036110,12.5,201004
00036110,12.5,200803
00036110,17.5,200803
00036110,17.5,200701
00036110,15.7,201004
00036110,12,201004
00036110,13.4,200009
00036110,13.4,199810
00036110,14.38,200803
00036110,14.38,200701
00036110,15,200803
00036110,15,200701
;;;;

proc sql;
create table three as select a.*,b.g as g1,b.yymm_e
from one a,
	 two b
where a.cusip=b.cusip and
	 b.yymm_e&amp;lt;= intnx('month',yymm_a,12,'same');
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Aug 2017 20:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385109#M92078</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-08-02T20:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385112#M92079</link>
      <description>&lt;P&gt;What's the issue?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 20:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385112#M92079</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-02T20:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385114#M92080</link>
      <description>&lt;P&gt;Hi Reeza, my issue is about date format. I have changed my date to date format, but I can't get the result I want&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 20:31:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385114#M92080</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-08-02T20:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385115#M92081</link>
      <description>&lt;P&gt;The result is very strang, and the same data I used before in the intnx function. The result was &amp;nbsp;right.&lt;/P&gt;&lt;P&gt;SAS Output&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;Obs CUSIP g yymm_a g1 yymm_e 1 2 3 4 5 6 7 8 9 10 11 12 13 &lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;00036020&lt;/TD&gt;&lt;TD&gt;22.25&lt;/TD&gt;&lt;TD&gt;199801&lt;/TD&gt;&lt;TD&gt;25.00&lt;/TD&gt;&lt;TD&gt;199201&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00036020&lt;/TD&gt;&lt;TD&gt;22.25&lt;/TD&gt;&lt;TD&gt;199801&lt;/TD&gt;&lt;TD&gt;25.00&lt;/TD&gt;&lt;TD&gt;199201&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00036020&lt;/TD&gt;&lt;TD&gt;22.25&lt;/TD&gt;&lt;TD&gt;199801&lt;/TD&gt;&lt;TD&gt;25.00&lt;/TD&gt;&lt;TD&gt;199201&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00036020&lt;/TD&gt;&lt;TD&gt;22.25&lt;/TD&gt;&lt;TD&gt;199801&lt;/TD&gt;&lt;TD&gt;25.00&lt;/TD&gt;&lt;TD&gt;199201&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00036020&lt;/TD&gt;&lt;TD&gt;17.00&lt;/TD&gt;&lt;TD&gt;199801&lt;/TD&gt;&lt;TD&gt;25.00&lt;/TD&gt;&lt;TD&gt;199201&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00036020&lt;/TD&gt;&lt;TD&gt;17.00&lt;/TD&gt;&lt;TD&gt;199801&lt;/TD&gt;&lt;TD&gt;25.00&lt;/TD&gt;&lt;TD&gt;199201&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00036020&lt;/TD&gt;&lt;TD&gt;17.00&lt;/TD&gt;&lt;TD&gt;199801&lt;/TD&gt;&lt;TD&gt;25.00&lt;/TD&gt;&lt;TD&gt;199201&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00036020&lt;/TD&gt;&lt;TD&gt;17.00&lt;/TD&gt;&lt;TD&gt;199801&lt;/TD&gt;&lt;TD&gt;25.00&lt;/TD&gt;&lt;TD&gt;199201&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00036020&lt;/TD&gt;&lt;TD&gt;12.00&lt;/TD&gt;&lt;TD&gt;199801&lt;/TD&gt;&lt;TD&gt;25.00&lt;/TD&gt;&lt;TD&gt;199201&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00036020&lt;/TD&gt;&lt;TD&gt;12.00&lt;/TD&gt;&lt;TD&gt;199801&lt;/TD&gt;&lt;TD&gt;25.00&lt;/TD&gt;&lt;TD&gt;199201&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00036020&lt;/TD&gt;&lt;TD&gt;12.00&lt;/TD&gt;&lt;TD&gt;199801&lt;/TD&gt;&lt;TD&gt;25.00&lt;/TD&gt;&lt;TD&gt;199201&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00036020&lt;/TD&gt;&lt;TD&gt;12.00&lt;/TD&gt;&lt;TD&gt;199801&lt;/TD&gt;&lt;TD&gt;25.00&lt;/TD&gt;&lt;TD&gt;199201&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00036020&lt;/TD&gt;&lt;TD&gt;15.00&lt;/TD&gt;&lt;TD&gt;199801&lt;/TD&gt;&lt;TD&gt;25.00&lt;/TD&gt;&lt;TD&gt;199201&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 02 Aug 2017 20:37:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385115#M92081</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-08-02T20:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385116#M92082</link>
      <description>&lt;P&gt;Step back for a second.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does this information (below) tell me? The code works, so this is a logic issue. But you've only shown the code logic, which works so we can't know what you want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Hi, I have problem with date format. Here is my dataset&amp;nbsp;and my code. I dont think I made any mistake, and I cant find the cause. Pls help me , thanks.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similarly with the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;The results are strange&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WIth only the information you've posted there, what response are you looking for?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 20:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385116#M92082</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-02T20:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385117#M92083</link>
      <description>&lt;P&gt;Reeza, I want to merge the two databases. but the only same variable is cusip, and I am sure that yymm_e is no more than 12m after yymm_a, so I do this.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 20:47:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385117#M92083</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-08-02T20:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385119#M92084</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132979"&gt;@lixuan&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;I am sure that yymm_e is no more than 12m after yymm_a&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But you've only stated that it needs to be less than a date value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;yymm_e&lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;intnx&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'month'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;yymm_a&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;12&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'same'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You'll join to any record that's less then the 12 months of the variable, which will end up with a large data set. What do you expect as output?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately I need to log out shortly for a few days (vacation!!!) so you should spend some time building an example that shows what you have and what you need. Using my 'mind reading machine', since you still haven't explained your problem, are you trying to merge the data with the closest date in the data set or with multiple records that are within a specified range?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 20:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385119#M92084</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-02T20:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385121#M92086</link>
      <description>&lt;P&gt;Hi Reeza, I will check my logic again, thank you and have a good vacation.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 20:59:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385121#M92086</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-08-02T20:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385144#M92097</link>
      <description>&lt;P&gt;Since your data set two has the first four records identical then anything that matches the first will match all 4. Similarly all the other duplicates is two will generate additional duplicate records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;instead of Intnx perhaps you want to look at using the the two dates in an INTCK function call and see if the result is between 0 and 12?&lt;/P&gt;
&lt;P&gt;without an example of the desired output I'm not sure of something more specific&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 22:42:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385144#M92097</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-02T22:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385163#M92103</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132979"&gt;@lixuan&lt;/a&gt;, try and change your last step to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table three as select a.*,b.g as g1,b.yymm_e
from one a,
	 two b
where a.cusip=b.cusip and
	 abs(intck('month',yymm_a,yymm_e))  &amp;lt;= 12;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Aug 2017 02:25:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385163#M92103</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-08-03T02:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385214#M92119</link>
      <description>&lt;P&gt;Sure, I understand that my problem is not the matter of date format, and I use the code to get the result. But there are too many duplicate observations producted by the rule of proc sql. &amp;nbsp;I only have variables cusip and yymm_ &amp;nbsp;which have some connections . I will be very appreciated if any suggestion. Thanks&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;a.yymm_a&amp;lt;= b.yymm_e&amp;lt;= intnx('month',a.yymm_a,12,'same');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Aug 2017 09:01:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385214#M92119</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-08-03T09:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385220#M92121</link>
      <description>&lt;P&gt;You did not marked is my previous posted code give the wanted results, and if not - what is wrong with it ?!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You ave not posted desired or expected results in order to check suggested code. Please do it -&amp;nbsp;&lt;/P&gt;
&lt;P&gt;otherwise we are just guessing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One more guess - try next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge one two;
  by;  /* concatenates datasets observations horizontally one by one */&lt;BR /&gt;&lt;/CODE&gt;&lt;CODE class="  language-sas"&gt;  if yymm_a &lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt; yymm_e &lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;intnx&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'month'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;yymm_a&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;12&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'same'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;h&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 09:27:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385220#M92121</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-08-03T09:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385233#M92122</link>
      <description>&lt;P&gt;There are 9 observations from one and 4 observations from two that mutually fulfill the condition of being within 12 months, so you get 9*4 = 36 observations in the output. That's what an outer join in SQL does.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you need to refine your rule. Start by formulating it in plain language, then exercise your rule logically, and once it works, convert it to code.&lt;/P&gt;
&lt;P&gt;Or you show the intended result you expected (from the tow datasets as posted in your OP), so we can work on that.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 10:17:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385233#M92122</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-03T10:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385265#M92127</link>
      <description>&lt;P&gt;Hi, Thank you all for your patience. Now the problem has become the matter of merge which had also puzzled me for a long time. The following is my example an the result I &amp;nbsp;want. My logic is very simple: I just wanna the company and date are same in both &amp;nbsp;datasets, and roe, roa are as they were. I always find it's hard to control the result in 'many-many' merge. thanks&amp;amp; regards.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input company$ roe date;
cards;
A 0.5 1995
A 0.2 1994
B 0.6 1998
;
data two;
input company$ roa date;
cards;
A 0.2 1995
A 0.3 1996
A 0.8 1995
B 0.7 1998
B 0.5 1998
C 0.2 1995
;&lt;BR /&gt;*result;
data want;
input company$ roe roa date;
cards;
A 0.5 0.2 1995
A  .  0.8 1995
B 0.6 0.7 1998
B  .  0.5 1998
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Aug 2017 12:39:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385265#M92127</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-08-03T12:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385296#M92129</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132979"&gt;@lixuan&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi, Thank you all for your patience. Now the problem has become the matter of merge which had also puzzled me for a long time. The following is my example an the result I &amp;nbsp;want. My logic is very simple: I just wanna the company and date are same in both &amp;nbsp;datasets, and roe, roa are as they were. I always find it's hard to control the result in 'many-many' merge. thanks&amp;amp; regards.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input company$ roe date;
cards;
A 0.5 1995
A 0.2 1994
B 0.6 1998
;
data two;
input company$ roa date;
cards;
A 0.2 1995
A 0.3 1996
A 0.8 1995
B 0.7 1998
B 0.5 1998
C 0.2 1995
;&lt;BR /&gt;*result;
data want;
input company$ roe roa date;
cards;
A 0.5 0.2 1995
A  .  0.8 1995
B 0.6 0.7 1998
B  .  0.5 1998
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This can be done with a little trickery in a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=one;
by company date;
run;

proc sort data=two;
by company date;
run;

data want;
format company roe roa date; * strictly for order of variables;
roe = .;
roa = .; * these two statements override the automatic retain of variables in datasets;
merge
  one (in=a)
  two (in=b)
;
by company date;
if a and b;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;company    roe    roa    date

   A       0.5    0.2    1995
   A        .     0.8    1995
   B       0.6    0.7    1998
   B        .     0.5    1998
&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Aug 2017 13:41:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385296#M92129</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-03T13:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385306#M92132</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, I liked your trick which is new to me.&lt;/P&gt;
&lt;P&gt;Please explain what do you mean by "automatic retain of variables"&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and when does it occur? Thanks ahead.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 14:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385306#M92132</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-08-03T14:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385327#M92143</link>
      <description>&lt;P&gt;I guess that without&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;roe &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;, variable A would have retain 0.5, then the second row in want would be&lt;/P&gt;&lt;PRE&gt; A  0.5     0.8    1995&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I don't know if my understanding is right. Also, I wonder whether &amp;nbsp;format function is necessary? I delete format and the result is same.&lt;/P&gt;&lt;P&gt;SAS Output&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;roe roa company date &lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;0.5&lt;/TD&gt;&lt;TD&gt;0.2&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1995&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;0.8&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1995&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0.6&lt;/TD&gt;&lt;TD&gt;0.7&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;1998&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;0.5&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;1998&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV align="center"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 03 Aug 2017 14:39:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385327#M92143</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-08-03T14:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385569#M92250</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, I liked your trick which is new to me.&lt;/P&gt;
&lt;P&gt;Please explain what do you mean by "automatic retain of variables"&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and when does it occur? Thanks ahead.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is a feature of the data step that does not sound logical at first, but is perfectly logical once one looks into the depth of the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We know that the data step sets all variables to missing at the start of an iteration, with the exception of those that are mentioned in a retain statement. But now think of the typical merge situation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input id dat1;
cards;
1 1
;
run;

data b;
input id dat2;
cards;
1 3
1 4
;
run;

data want;
merge
  a
  b
;
by id;
iter = _n_;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the result&lt;/P&gt;
&lt;PRE&gt;id    dat1    dat2    iter

 1      1       3       1 
 1      1       4       2 &lt;/PRE&gt;
&lt;P&gt;we can clearly see that dat1 was not missing in the second iteration of the data step. That is not because the data step rereads dataset a, but because the variables from the dataset are not set to missing (and therefore retained); if another observation for id 1 had been present, its values would have overwritten the PDV, but so they simply stay.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the set or merge statement also defines the point in time when a dataset is read, manipulating variables before is effective.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 05:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385569#M92250</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-04T05:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385570#M92251</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132979"&gt;@lixuan&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I guess that without&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;roe &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;, variable A would have retain 0.5, then the second row in want would be&lt;/P&gt;
&lt;PRE&gt; A  0.5     0.8    1995&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;I don't know if my understanding is right. Also, I wonder whether &amp;nbsp;format function is necessary? I delete format and the result is same.&lt;/P&gt;
&lt;P&gt;SAS Output&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;roe roa company date
&lt;TABLE cellpadding="5" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;0.5&lt;/TD&gt;
&lt;TD&gt;0.2&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD&gt;1995&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;0.8&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD&gt;1995&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;0.6&lt;/TD&gt;
&lt;TD&gt;0.7&lt;/TD&gt;
&lt;TD&gt;B&lt;/TD&gt;
&lt;TD&gt;1998&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;0.5&lt;/TD&gt;
&lt;TD&gt;B&lt;/TD&gt;
&lt;TD&gt;1998&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV align="center"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You perfectly understood what's happening.&lt;/P&gt;
&lt;P&gt;The format is just there so that the horizontal order of variables(columns) is forced to be the one you showed in your example "want" data. Nothing more, it does not influence the actual formats of the variables, as those are taken from the dataset metadata when the merge statement is compiled.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that variables are added to the PDV (program data vector) in the sequence they are encountered by the data step compiler. Attributes that can be changed (like labels or formats, but not the type!) are set from the last statement encountered that explicitly (like a format statement) or implicitly (like a set or merge statement) sets them.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 06:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385570#M92251</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-04T06:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: The subject of date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385574#M92253</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;Thanks, I get your idea and have more comprehension of funtion merge. But I do think the result of &amp;nbsp;merge or proc sql(I prefer this and think it is preciser than data step) is very hard to be controled in the situation of duplicate data.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 06:31:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-subject-of-date-format/m-p/385574#M92253</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-08-04T06:31:17Z</dc:date>
    </item>
  </channel>
</rss>

