<?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 get data according to the benchmark of other database in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-data-according-to-the-benchmark-of-other-database/m-p/377678#M90711</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input company$ date  profit;
datalines;
a 199701 5
b 201404 6
f 200004 78
;
run;

data want
input company$ date  EPS;
datalines;
a 199608 5
a 199706 30
a 199605 4
a 199712 9
a 199806 10
c 201404 6
k 200004 78
n 198607 56
a 198504 3
b 201304 3
b 201305 6
b 201306 8
b 201504 80
b 201603 5

;
run; 

/*the result should be*/
data rusult;
input company$ date  EPS;
datalines;
a 199608 5
a 199706 30
a 199605 4
a 199712 9
b 201304 3
b 201305 6
b 201306 8
b 201504 80 
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;ok, I want the result as above. Because 'a' and 'b' are also in data 'have', they should be selected. As for 'b', the date in 'have' is 201404, so the date in 'want' should be in (201304 to 201303) and in (201405 to 201504), and I get the 'EPS' I want. The last observation of b in data 'want' should be excluded for the date is out of one year range. I don't know if I express my idea well enough to be understood. If any question , pls let me know. Thank u very much.&lt;/P&gt;</description>
    <pubDate>Thu, 20 Jul 2017 09:01:21 GMT</pubDate>
    <dc:creator>lixuan</dc:creator>
    <dc:date>2017-07-20T09:01:21Z</dc:date>
    <item>
      <title>How to get data according to the benchmark of other database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-data-according-to-the-benchmark-of-other-database/m-p/377668#M90708</link>
      <description>&lt;P&gt;Hi, I have two database like the following. Maybe data &amp;nbsp;'have' is a event-happen day and data 'want' is some characters of the company. What i wanna is to find out the change of EPS of the company before and after the event-day, so I hope to get the data of the same company from database want and have. The time is 12 monthes before and 12 monthes after event day (the date of data have). I feel its so hard for me .&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input company$ date  profit;
datalines;
a 199701 5
b 201404 6
f 200004 78
;
run;

data want
input company$ date  EPS;
datalines;
a 199701 5
c 201404 6
k 200004 78
n 198607 56
a 198504 3
b 197604 3
;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2017 07:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-data-according-to-the-benchmark-of-other-database/m-p/377668#M90708</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-20T07:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to get data according to the benchmark of other database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-data-according-to-the-benchmark-of-other-database/m-p/377672#M90710</link>
      <description>&lt;P&gt;Could you give us the example how the resulting dataset should look like?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2017 08:24:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-data-according-to-the-benchmark-of-other-database/m-p/377672#M90710</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-07-20T08:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to get data according to the benchmark of other database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-data-according-to-the-benchmark-of-other-database/m-p/377678#M90711</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input company$ date  profit;
datalines;
a 199701 5
b 201404 6
f 200004 78
;
run;

data want
input company$ date  EPS;
datalines;
a 199608 5
a 199706 30
a 199605 4
a 199712 9
a 199806 10
c 201404 6
k 200004 78
n 198607 56
a 198504 3
b 201304 3
b 201305 6
b 201306 8
b 201504 80
b 201603 5

;
run; 

/*the result should be*/
data rusult;
input company$ date  EPS;
datalines;
a 199608 5
a 199706 30
a 199605 4
a 199712 9
b 201304 3
b 201305 6
b 201306 8
b 201504 80 
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;ok, I want the result as above. Because 'a' and 'b' are also in data 'have', they should be selected. As for 'b', the date in 'have' is 201404, so the date in 'want' should be in (201304 to 201303) and in (201405 to 201504), and I get the 'EPS' I want. The last observation of b in data 'want' should be excluded for the date is out of one year range. I don't know if I express my idea well enough to be understood. If any question , pls let me know. Thank u very much.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2017 09:01:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-data-according-to-the-benchmark-of-other-database/m-p/377678#M90711</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-20T09:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to get data according to the benchmark of other database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-data-according-to-the-benchmark-of-other-database/m-p/377695#M90716</link>
      <description>&lt;P&gt;Look at this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have_base;
input company$ _date:$6. profit;
date = input(_date !! '01',yymmdd8.);
format date yymmn6.;
drop _date;
datalines;
a 199701 5
b 201404 6
f 200004 78
;
run;

data have_event;
input company$ _date:$6. EPS;
date = input(_date !! '01',yymmdd8.);
format date yymmn6.;
drop _date;
datalines;
a 199608 5
a 199706 30
a 199605 4
a 199712 9
a 199806 10
c 201404 6
k 200004 78
n 198607 56
a 198504 3
b 201304 3
b 201305 6
b 201306 8
b 201504 80
b 201603 5
;
run;

proc sort data=have_event;
by company;
run;

data want;
merge
  have_base (in=b rename=(date=date_b))
  have_event (in=e)
;
by company;
if b and e;
if abs(intck('month',date,date_b)) &amp;lt;= 12;
drop profit date_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    EPS      date

   a         5    199608
   a        30    199706
   a         4    199605
   a         9    199712
   b         3    201304
   b         6    201305
   b         8    201306
   b        80    201504
&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Jul 2017 11:01:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-data-according-to-the-benchmark-of-other-database/m-p/377695#M90716</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-07-20T11:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to get data according to the benchmark of other database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-data-according-to-the-benchmark-of-other-database/m-p/377711#M90724</link>
      <description>&lt;P&gt;Oh, great! &amp;nbsp;it's amazing! You give me a great help. Thanks a lot&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2017 12:08:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-data-according-to-the-benchmark-of-other-database/m-p/377711#M90724</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-20T12:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to get data according to the benchmark of other database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-data-according-to-the-benchmark-of-other-database/m-p/378386#M90896</link>
      <description>&lt;P&gt;Hi, I tried to get the data not in pre and after benchmark time, insteadly I wanna get the datas before the benchmark, &amp;nbsp;so i revised the code , but it didin't wok. Could you help me again? Thanks&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have_base;
input company$ _date:$6. profit;
date = input(_date !! '01',yymmdd8.);
format date yymmn6.;
drop _date;
datalines;
a 199701 5
b 201404 6
f 200004 78
;
run;

data have_event;
input company$ _date:$6. EPS;
date = input(_date !! '01',yymmdd8.);
format date yymmn6.;
drop _date;
datalines;
a 199608 5
a 199706 30
a 199605 4
a 199712 9
a 199806 10
c 201404 6
k 200004 78
n 198607 56
a 198504 3
b 201304 3
b 201305 6
b 201306 8
b 201504 80
b 201603 5
;
run;

proc sort data=have_event;
by company;
run;

data want;
merge
  have_base (in=b rename=(date=date_b))
  have_event (in=e)
;
by company;
if b and e;
/*if date &amp;gt;= intnx('month',date_b, -12);*/
if 0&amp;gt;=intck('month',date,date_b) &amp;gt;=-12;
drop profit date_b;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The result&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;company EPS date &lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;199806&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;80&lt;/TD&gt;&lt;TD&gt;201504&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;201603&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 22 Jul 2017 06:29:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-data-according-to-the-benchmark-of-other-database/m-p/378386#M90896</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-22T06:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to get data according to the benchmark of other database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-data-according-to-the-benchmark-of-other-database/m-p/378429#M90922</link>
      <description>&lt;P&gt;Hi, I got the answer use the code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge
  have_base (in=b rename=(date=date_b))
  have_event (in=e)
;
by company;
if b and e;
if intnx('month',date_b, -12)&amp;lt;=date&amp;lt;=date_b;
/*if 0&amp;gt;=intck('month',date,date_b) &amp;gt;=-12;*/
drop profit date_b;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;But actually my datas' structure is like this, and a in dataset 'have_base' has duplicated observations. But I also want it to be a benchmark.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have_base;
input company$ _date:$6. profit;
date = input(_date !! '01',yymmdd8.);
format date yymmn6.;
drop _date;
datalines;
a 199701 5
a 199606 9
b 201404 6
f 200004 78
;
run;

data have_event;
input company$ _date:$6. EPS;
date = input(_date !! '01',yymmdd8.);
format date yymmn6.;
drop _date;
datalines;
a 199608 5
a 199706 30
a 199605 4
a 199712 9
a 199806 10
c 201404 6
k 200004 78
n 198607 56
a 198504 3
b 201304 3
b 201305 6
b 201306 8
b 201504 80
b 201603 5
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to get the result :&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;a 199608 5&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;a 199605 4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;a 199605 4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;b 201304 3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;b 201305 6&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;b 201306 8&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;actually, I have no any idea of that. Thanks a lot .&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 15:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-data-according-to-the-benchmark-of-other-database/m-p/378429#M90922</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-22T15:43:32Z</dc:date>
    </item>
  </channel>
</rss>

