<?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: Convert Date and sort out data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-Date-and-sort-out-data/m-p/332004#M74688</link>
    <description>&lt;P&gt;For your first question - converting dates - run next test code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    dq = '2016q3';                     /* variable given in char type */
    dt = input('20160728',yymmdd8.);   /* converting given char date into sas numeric date */
    format dt yyq6.;                   /* format defines how to display the date, in this case: yyyyQn */&lt;BR /&gt;&lt;BR /&gt;    /* next line compares the quarter to the date - are they the same quarter */
    if upcase(dq) = strip(put(dt,yyq6.)) then put 'OK'; else put 'NOK';
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Try to have your own code for merging. Post your code and what issues you face.&lt;/P&gt;
&lt;P&gt;You better create a small sample for test, to save time and make it simple.&lt;/P&gt;</description>
    <pubDate>Sun, 12 Feb 2017 21:03:10 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-02-12T21:03:10Z</dc:date>
    <item>
      <title>Convert Date and sort out data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Date-and-sort-out-data/m-p/331904#M74668</link>
      <description>&lt;P&gt;Hi i am a begginer on SAS and i need some help:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My first problem is converting the date, i have the following format : 20020331 so YYYYMMDD and i would like to have the year and the quarter so this format 2002Q1 (YYYYQQ ).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My second problem is about merging two databases based on mutual information included on both of them: my first database is a large database containing &amp;nbsp;the date, the ID number and other variables for example:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Global Company Key&lt;/TD&gt;&lt;TD&gt;Fiscal Data Year and Quarter&lt;/TD&gt;&lt;TD&gt;Current Assets - Total&lt;/TD&gt;&lt;TD&gt;Assets - Total&lt;/TD&gt;&lt;TD&gt;Cash and Short-Term Investments&lt;/TD&gt;&lt;TD&gt;Long-Term Debt - Total&lt;/TD&gt;&lt;TD&gt;Current Liabilities - Total&lt;/TD&gt;&lt;TD&gt;Liabilities - Total&lt;/TD&gt;&lt;TD&gt;Net Income (Loss)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1034&lt;/TD&gt;&lt;TD&gt;2002Q1&lt;/TD&gt;&lt;TD&gt;639,409&lt;/TD&gt;&lt;TD&gt;2367,051&lt;/TD&gt;&lt;TD&gt;9,689&lt;/TD&gt;&lt;TD&gt;880,936&lt;/TD&gt;&lt;TD&gt;368,339&lt;/TD&gt;&lt;TD&gt;1373,972&lt;/TD&gt;&lt;TD&gt;-31,94&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1034&lt;/TD&gt;&lt;TD&gt;2002Q2&lt;/TD&gt;&lt;TD&gt;695,609&lt;/TD&gt;&lt;TD&gt;2448,679&lt;/TD&gt;&lt;TD&gt;12,884&lt;/TD&gt;&lt;TD&gt;899,789&lt;/TD&gt;&lt;TD&gt;381,368&lt;/TD&gt;&lt;TD&gt;1384,204&lt;/TD&gt;&lt;TD&gt;10,159&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1034&lt;/TD&gt;&lt;TD&gt;2002Q3&lt;/TD&gt;&lt;TD&gt;700,596&lt;/TD&gt;&lt;TD&gt;2416,691&lt;/TD&gt;&lt;TD&gt;41,2&lt;/TD&gt;&lt;TD&gt;907,505&lt;/TD&gt;&lt;TD&gt;345,285&lt;/TD&gt;&lt;TD&gt;1357,847&lt;/TD&gt;&lt;TD&gt;-5,946&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And my second database contains the date and the ID number for example:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;RankDate&lt;/TD&gt;&lt;TD&gt;RankdateQ&lt;/TD&gt;&lt;TD&gt;targetGkey&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20091102&lt;/TD&gt;&lt;TD&gt;2009Q4&lt;/TD&gt;&lt;TD&gt;1034&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to extract the variables included in the first database based on specific date included in the second one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It would be really helpfull if someone can help, i am struggling with this for quiet a while.&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 01:32:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Date-and-sort-out-data/m-p/331904#M74668</guid>
      <dc:creator>moumes</dc:creator>
      <dc:date>2017-02-12T01:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Date and sort out data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Date-and-sort-out-data/m-p/331930#M74672</link>
      <description>&lt;P&gt;1) Use proc contents to post your variable names on each database with their type and format&lt;/P&gt;
&lt;P&gt;2) In your sample - first database have year 2002 while the second is 2009.&lt;BR /&gt;&amp;nbsp; &amp;nbsp; In such case there is no matching and you'll get empty result.&lt;/P&gt;
&lt;P&gt;3) Please post your sample data in a way we don't need to retype the data&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; in order to run a test&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 05:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Date-and-sort-out-data/m-p/331930#M74672</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-12T05:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Date and sort out data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Date-and-sort-out-data/m-p/331965#M74678</link>
      <description>&lt;P&gt;Thank you for your reply, those are the databases i am using :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;as you see in the first database i have the Global Company Key which is a variable that identifies the company and values for other variables for each quarter from 2002 to 2013.&lt;/P&gt;&lt;P&gt;In the second database i have the Global Company Key and a specific date in this format YYYYMMDD, i need to convert this format to quarters and then extract the value of the variables included in the first database &amp;nbsp;based on the dated specified &amp;nbsp;in the second one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you a lot for your hep.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 15:44:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Date-and-sort-out-data/m-p/331965#M74678</guid>
      <dc:creator>moumes</dc:creator>
      <dc:date>2017-02-12T15:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Date and sort out data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Date-and-sort-out-data/m-p/332004#M74688</link>
      <description>&lt;P&gt;For your first question - converting dates - run next test code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    dq = '2016q3';                     /* variable given in char type */
    dt = input('20160728',yymmdd8.);   /* converting given char date into sas numeric date */
    format dt yyq6.;                   /* format defines how to display the date, in this case: yyyyQn */&lt;BR /&gt;&lt;BR /&gt;    /* next line compares the quarter to the date - are they the same quarter */
    if upcase(dq) = strip(put(dt,yyq6.)) then put 'OK'; else put 'NOK';
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Try to have your own code for merging. Post your code and what issues you face.&lt;/P&gt;
&lt;P&gt;You better create a small sample for test, to save time and make it simple.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 21:03:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Date-and-sort-out-data/m-p/332004#M74688</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-12T21:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Date and sort out data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Date-and-sort-out-data/m-p/332032#M74692</link>
      <description>&lt;P&gt;I don't know how you imported your data. I used proc import, using the dbms=xlsx option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using that method, the company IDs were character in one file, numeric in the other.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similarly, the dates in one file were numbers rather than dates and, in the other, were quarters represented as a character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code I ran to solve your problem of merging the two files:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc import datafile="/folders/myfolders/first_database.xlsx" 
  out=first_database replace dbms=xlsx;
  getnames=yes;
  mixed=yes;
  sheet='Sheet1';
  usedate=yes;
  scantime=yes;
run;

proc import datafile="/folders/myfolders/second database.xlsx" 
  out=second_database replace dbms=xlsx;
  getnames=yes;
  mixed=yes;
  sheet='Sheet1';
  usedate=yes;
  scantime=yes;
run;

data first_database (drop=_:);
  set first_database (rename=(
  fiscal_data_year_and_quarter=
   _fiscal_data_year_and_quarter));
  format fiscal_data_year_date date9.;
  fiscal_data_year_date=
   mdy(substr(_fiscal_data_year_and_quarter,6,1)*3,1,
   substr(_fiscal_data_year_and_quarter,1,4));
  fiscal_data_year_and_quarter=put(fiscal_data_year_date,yyq6.);
run;

proc sort data=first_database;
  by global_company_key;
run;

options datestyle=YMD;
data second_database (drop=_:);
  set second_database (rename=(
  announcedate=
   _announcedate
   global_company_key=_global_company_key));
  format announcedate date9.;
  announcedate=
   input(strip(_announcedate),anydtdte8.);
  global_company_key=input(_global_company_key,8.);
run;

proc sort data=second_database;
  by global_company_key;
run;

data want;
  merge first_database second_database;
  by global_company_key;
run;
&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 22:54:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Date-and-sort-out-data/m-p/332032#M74692</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-12T22:54:36Z</dc:date>
    </item>
  </channel>
</rss>

