<?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: Building report using PROC SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324318#M271288</link>
    <description>&lt;P&gt;Sorry, you mixing up terms here. &amp;nbsp;SQL is not a report function, it is a query language. &amp;nbsp;So your querying a dataset to return only those coded values and you want the observations to appear in a certain order which is not the alphabetic order, correct? &amp;nbsp;If so then you need to apply a format:&lt;/P&gt;
&lt;P&gt;proc format;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; value $xyz&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 'TQ'=2...&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or alternatively case when 'TQ' then 1... end as ORD_VAR, and order by ORD_VAR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I.e. so you create a numerical version of the code which can be used to sort them. &amp;nbsp;If you provide some tests data, in the form of a datastep, can provide code.&lt;/P&gt;</description>
    <pubDate>Thu, 12 Jan 2017 16:30:18 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-01-12T16:30:18Z</dc:date>
    <item>
      <title>Building report using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324305#M271287</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been using SAS for under a year so please bear with me as I articulate the problem I am having. &amp;nbsp;I'm trying to run a report using PROC SQL and I need to include a field separately&amp;nbsp;on the report. &amp;nbsp;For example, I need to include a variable called "TQ" and if it is present I then need to include variables "SB", "SD", "SF", etc. &amp;nbsp;The way I have it coded now includes everything together.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ACTVT_RSLT_FACT.TRN_CD IN ( 'TQ', 'SB', 'SD', 'SE', 'SF', 'SJ', 'SK', 'SL', 'SM', 'SO', 'SP', 'SS', 'SU', 'SV', 'SZ', 'TE' )&lt;/PRE&gt;&lt;P&gt;I need to separate TQ from the rest of the tran codes listed on the report. &amp;nbsp;I tried this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ACTVT_RSLT_FACT.TRN_CD LIKE 'TQ'

AND

ACTVT_RSLT_FACT.TRN_CD IN ( 'SB', 'SD', 'SE', 'SF', 'SJ', 'SK', 'SL', 'SM', 'SO', 'SP', 'SS', 'SU', 'SV', 'SZ', 'TE' )&lt;/PRE&gt;&lt;P&gt;But of course that didn't work. &amp;nbsp;I'm building a report that shows TQ followed by SB, SD, SE so then I can calculate the days between them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope all this made sense and someone is able to help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Justin&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2017 16:17:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324305#M271287</guid>
      <dc:creator>jmoore168</dc:creator>
      <dc:date>2017-01-12T16:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: Building report using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324318#M271288</link>
      <description>&lt;P&gt;Sorry, you mixing up terms here. &amp;nbsp;SQL is not a report function, it is a query language. &amp;nbsp;So your querying a dataset to return only those coded values and you want the observations to appear in a certain order which is not the alphabetic order, correct? &amp;nbsp;If so then you need to apply a format:&lt;/P&gt;
&lt;P&gt;proc format;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; value $xyz&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 'TQ'=2...&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or alternatively case when 'TQ' then 1... end as ORD_VAR, and order by ORD_VAR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I.e. so you create a numerical version of the code which can be used to sort them. &amp;nbsp;If you provide some tests data, in the form of a datastep, can provide code.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2017 16:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324318#M271288</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-12T16:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Building report using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324389#M271289</link>
      <description>&lt;P&gt;Hi RW9 thank you for your quick response. &amp;nbsp;I'm learning the correct terminology already. &amp;nbsp;Here is some sample code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;WHERE
    (ACCT_DIM.ACCT_ID=ACTVT_RSLT_FACT.ACCT_ID)
    AND  
    ( STATUS_CD_LOOKUP.STATUS_CD=ACCT_DIM.STATUS_CD  )
    AND
    (ACCT_DIM.ACCT_ID=TRANSACTION_FACT.ACCT_ID)
    AND
    ( ATTORNEY_CD_LOOKUP.RECOVERER_CD=ACCT_DIM.ATTORNEY_CD  )
    AND
    ACTVT_RSLT_FACT.TRN_CD IN ( 'TQ', 'SB', 'SD', 'SE', 'SF', 'SJ', 'SK', 'SL', 'SM', 'SO', 'SP', 'SS', 'SU', 'SV', 'SZ', 'TE' )
    AND
    ACTVT_RSLT_FACT.TRN_DT BETWEEN '1NOV2016'd and TODAY()-1
    AND
    TRANSACTION_FACT.TRN_CD LIKE '1S'
;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need the report to pull tran code TQ first. &amp;nbsp;If TQ is found THEN I want to query tran codes&amp;nbsp;'SB', 'SD', 'SE', 'SF', 'SJ', 'SK', 'SL', 'SM', 'SO', 'SP', 'SS', 'SU', 'SV', 'SZ', 'TE' along with the tran_dt for TQ and the other codes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2017 20:27:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324389#M271289</guid>
      <dc:creator>jmoore168</dc:creator>
      <dc:date>2017-01-12T20:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: Building report using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324405#M271290</link>
      <description>&lt;P&gt;&lt;STRONG&gt;It really helps to provide a few example records of input data and then show the desired result&lt;/STRONG&gt;. You don't need to provide records for all possible values but it does help to have some "matches" and some that don't.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As it is when you say: tran code TQ first. &amp;nbsp;If TQ is found THEN I want to query tran codes&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it sounds like you are looking at a single variable with a single value. If the trn_cd='TQ' then it can't find any other codes. So are you looking in another variable? Or another record? If so, how do we know which other record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And without a lot of work SQL does not really have any concept of "first", "last"&amp;nbsp;or "before". Do mean matching some other identifier(s) and the date for the 'SB', 'SD', 'SE', 'SF', 'SJ', 'SK', 'SL', 'SM', 'SO', 'SP', 'SS', 'SU', 'SV' codes are attached to records with a date greater than for the TQ value?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2017 21:42:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324405#M271290</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-01-12T21:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: Building report using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324407#M271291</link>
      <description>&lt;P&gt;I think I would parse my data some before starting in with the SQL queries.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You ony want records where TRN_CD is TQ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TQs_only;
  set initial_file;
  if trn_cd = 'TQ';
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Parse things down with a bunch of that WHERE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might also want to look at an SQL CASE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2017 21:33:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324407#M271291</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-01-12T21:33:04Z</dc:date>
    </item>
    <item>
      <title>Re: Building report using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324408#M271292</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how it is now:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ACCT_NUM	TRN_CD	TRN_DT	
**************   TQ	12/16/2016

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how I want it to display&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ACCT_NUM     TRN_CD_TQ   TRN_DT	      Tran_Code_Other	  TRN_DATE	   
************	TQ	  12/16/2016	*OTHER TRN_CODE	  *OTHR TRN_DATE&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2017 21:30:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324408#M271292</guid>
      <dc:creator>jmoore168</dc:creator>
      <dc:date>2017-01-12T21:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: Building report using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324410#M271293</link>
      <description>Where do tran_code_other and trn_date come from?&lt;BR /&gt;How about a complete SQL statement? How about some sample data?</description>
      <pubDate>Thu, 12 Jan 2017 21:34:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324410#M271293</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-01-12T21:34:43Z</dc:date>
    </item>
    <item>
      <title>Re: Building report using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324431#M271294</link>
      <description>&lt;P&gt;Seems like you need to do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table acct as
select acct_num, trn_cd, trn_dt
from ....
WHERE
    (ACCT_DIM.ACCT_ID=ACTVT_RSLT_FACT.ACCT_ID)
    AND  
    ( STATUS_CD_LOOKUP.STATUS_CD=ACCT_DIM.STATUS_CD  )
    AND
    (ACCT_DIM.ACCT_ID=TRANSACTION_FACT.ACCT_ID)
    AND
    ( ATTORNEY_CD_LOOKUP.RECOVERER_CD=ACCT_DIM.ATTORNEY_CD  )
    AND
    ACTVT_RSLT_FACT.TRN_CD IN ( 'TQ', 'SB', 'SD', 'SE', 'SF', 'SJ', 'SK', 'SL', 'SM', 'SO', 'SP', 'SS', 'SU', 'SV', 'SZ', 'TE' )
    AND
    ACTVT_RSLT_FACT.TRN_DT BETWEEN '1NOV2016'd and TODAY()-1
    AND
    TRANSACTION_FACT.TRN_CD LIKE '1S';
select tq.*, x.trn_cd as TranCodeOther, x.trn_dt as trn_date
from 
	acct as tq inner join
	acct as x on tq.acct_num=x.acct_num
where tq.trn_cd = "TQ" and x.trn_cd ne "TQ";
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Jan 2017 23:28:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324431#M271294</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-01-12T23:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: Building report using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324491#M271295</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select  A.ACCT_NUM,
          A.TRN_CD,
          B.TRN_CD as TRN_CODE_OTHER,
          B.TRN_DT
  from    (select * from ACCOUNTS where TRN_CD="TQ") A
  left join (select * from ACCOUNTS where TRN_CD ne "TQ") B
  on      A.ACCT_NUM=B.ACCT_NUM;
quit;&lt;/PRE&gt;
&lt;P&gt;Do note for the future, to post a well formed question, start by displaying test data (a few rows, in the form of a datastep) and what the output should look like. &amp;nbsp;We can't see what your doing or what you have/want without it.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2017 09:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/324491#M271295</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-13T09:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: Building report using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/325345#M271296</link>
      <description>&lt;P&gt;Hi PG Stats&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for the delay as I was out of the office due to the holiday.&amp;nbsp; I used your code but I received an error message&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ERROR: File WORK.ACCT.DATA does not exist.
ERROR: File WORK.ACCT.DATA does not exist.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The query did produce observations but it was the same as before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ACCT_NUM	TRN_CD	TRN_DT
123456789	SF	        15Dec2016 
123456789	TQ	        16Dec2016


&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the entire code I used to run it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC SQL;
create table automation_exception as

SELECT
    ACCT_DIM.ACCT_NUM,
    ACTVT_RSLT_FACT.TRN_CD,
    ACTVT_RSLT_FACT.TRN_DT,
    ACTVT_RSLT_FACT.TRN_NOTE,
    ACTVT_RSLT_FACT.USERID,
    STATUS_CD_LOOKUP.STATUS_CD,
    ACCT_DIM.LST_STATUS_CD,
    ACCT_DIM.LST_STATUS_CHG_DT,
    ACCT_DIM.DT_ASSIGNED,
    ACCT_DIM.ATTORNEY_CD,
    ATTORNEY_CD_LOOKUP.RECOVERER_CD_DESC,
    ACCT_DIM.ACCT_PURGED_FLG,
    TRANSACTION_FACT.TRN_CD
       
FROM
    RDWP0.ACCT_DIM,
    RDWP0.ACTVT_RSLT_FACT,
    RDWP0.STATUS_CD_LOOKUP,
    RDWP0.TRANSACTION_FACT,
    RDWP0.RECOVERER_CD_LOOKUP  ATTORNEY_CD_LOOKUP


WHERE
    (ACCT_DIM.ACCT_ID=ACTVT_RSLT_FACT.ACCT_ID)
    AND  
    ( STATUS_CD_LOOKUP.STATUS_CD=ACCT_DIM.STATUS_CD  )
    AND
    (ACCT_DIM.ACCT_ID=TRANSACTION_FACT.ACCT_ID)
    AND
    ( ATTORNEY_CD_LOOKUP.RECOVERER_CD=ACCT_DIM.ATTORNEY_CD  )
    AND
    ACTVT_RSLT_FACT.TRN_CD IN ( 'TQ', 'SB', 'SD', 'SE', 'SF', 'SJ', 'SK', 'SL', 'SM', 'SO', 'SP', 'SS', 'SU', 'SV', 'SZ', 'TE' )
    AND
    ACTVT_RSLT_FACT.TRN_DT BETWEEN '1NOV2016'd and TODAY()-1
    AND
    TRANSACTION_FACT.TRN_CD LIKE '1S';

  SELECT tq.*, x.trn_cd as TranCodeOther, x.trn_dt as trn_date

  From
         acct as tq inner join
         acct as x on tq.acct_num=x.acct_num
  Where
         tq.trn_cd = "TQ" and x.trn_cd ne "TQ";

;
QUIT;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your assistance.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 16:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/325345#M271296</guid>
      <dc:creator>jmoore168</dc:creator>
      <dc:date>2017-01-17T16:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: Building report using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/325362#M271297</link>
      <description>&lt;P&gt;Thank you so much RW9.&amp;nbsp; I was able to separate TQ from the rest of the tran codes.&amp;nbsp; However what would be the solution to add trn_dt for TQ and the other trn_cd's?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here it is now:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ACCT_NUM	TRN_CD	TRN_CODE_OTHER	TRN_DT
123456789	  TQ	      SF	    15Dec2016&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like it to show:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ACCT_NUM	TRN_CD	TRN_CODE_OTHER	TRN_DT		&lt;STRONG&gt;Diff_Between_TQ_and_TRN_CODE_OTHER(TRN_DT)&lt;/STRONG&gt;
123456789	  TQ	      SF	    15Dec2016&lt;/PRE&gt;&lt;P&gt;OR&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ACCT_NUM	TRN_CD	TRN_CODE_OTHER	&lt;STRONG&gt;TQ(TRN_DATE)	TRN_CODE_OTHER(TRN_DT)&lt;/STRONG&gt;
123456789	  TQ	      SF	    &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second option is fine since I can create a formula in excel to calculate the difference between dates.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 17:23:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/325362#M271297</guid>
      <dc:creator>jmoore168</dc:creator>
      <dc:date>2017-01-17T17:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: Building report using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/325592#M271298</link>
      <description>&lt;P&gt;Well, SQL is straight forward, &amp;nbsp;You Select the variables or calculations From the dataset{s} you want, and Join them if there is more than one. &amp;nbsp;This code:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select  A.ACCT_NUM,
          A.TRN_CD,
          A.TRT_DT,
          B.TRN_CD as TRN_CODE_OTHER,
          B.TRN_DT,
          A.TRN_DT - B.TRN_DT as DIFF_BETWEEN
  from    (select * from ACCOUNTS where TRN_CD="TQ") A
  left join (select * from ACCOUNTS where TRN_CD ne "TQ") B
  on      A.ACCT_NUM=B.ACCT_NUM;
quit;&lt;/PRE&gt;
&lt;P&gt;Will give the diff between. &amp;nbsp;However, bear in mind that the left join will take all non TQ rows and add them to the TQ row, so you may end up with multiple rows. &amp;nbsp;If you have this, then either left join based on exact TRN_CD="SF", or transpose your data up - which would be simplest:&lt;/P&gt;
&lt;PRE&gt;/* Assumes sorted */
proc transpose data=have out=tran_dates;
  by acct_num;
  var trn_dt;
  id trn_cd;
  idlabel trn_cd;
run;
&lt;/PRE&gt;
&lt;P&gt;This will give you a table something like:&lt;/P&gt;
&lt;P&gt;ACCT_NUM &amp;nbsp; &amp;nbsp;SF &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TQ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; UV&lt;/P&gt;
&lt;P&gt;0000000001 &amp;nbsp; &amp;nbsp;12JAN2012 &amp;nbsp; &amp;nbsp; 01DEC2011 &amp;nbsp;13MAR2011&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whic you can then simlpy process with if statements in a datastep, or use arrays on.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2017 09:20:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/325592#M271298</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-18T09:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: Building report using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/326492#M271299</link>
      <description>This query started talking about transaction codes and now it appears to be about an account.&lt;BR /&gt;&lt;BR /&gt;There probably needs to be an inner join of 2 streams of data selected from the original.&lt;BR /&gt;The first stream identifies accounts for which a TQ is present and the second stream is the other transactions (subject to being not too old)&lt;BR /&gt;The join is on account number.&lt;BR /&gt;The date of the TQ transaction acts like an opening-date.&lt;BR /&gt;The output of the join generates multiple rows per account number. However it seems the requested shape is one row per account with columns for each transaction thpe.&lt;BR /&gt;&lt;BR /&gt;It is not obvious whether there might be multiple transaction for each transaction type, nor how to handle that.&lt;BR /&gt;If the data are unique by transaction type within each account, a transpose is needed. However for non-unique, deduplication needs to have rules defined.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 21 Jan 2017 09:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-report-using-PROC-SQL/m-p/326492#M271299</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-01-21T09:16:37Z</dc:date>
    </item>
  </channel>
</rss>

