<?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: proc compare between sql left join and proc transpose not getting the same result ? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/proc-compare-between-sql-left-join-and-proc-transpose-not/m-p/771292#M30950</link>
    <description>&lt;P&gt;Sounds like you are expecting the two different methods to produce the same output.&lt;/P&gt;
&lt;P&gt;Do you know which one is right?&lt;/P&gt;
&lt;P&gt;What is it you are trying to do?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please describe the meaning of the two input datasets and the meaning of the result you are trying to create.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Sep 2021 03:08:43 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-09-30T03:08:43Z</dc:date>
    <item>
      <title>proc compare between sql left join and proc transpose not getting the same result ?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-compare-between-sql-left-join-and-proc-transpose-not/m-p/771287#M30949</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;length epoch $10. ;&lt;BR /&gt;input usubjid sstdtc sendtc epoch $ count;&lt;BR /&gt;informat sstdtc date9. sendtc date9.;&lt;BR /&gt;format sstdtc sendtc yymmdd10.;&lt;BR /&gt;datalines;&lt;BR /&gt;100 01JAN2010 15JAN2010 Screening 1&lt;BR /&gt;100 15JAN2010 15JUL2010 Treatment 2&lt;BR /&gt;100 16JUL2010 20DEC2010 Follow-up 3&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data = have out = have_sort;&lt;BR /&gt;by usubjid count;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have1;&lt;BR /&gt;input usubjid adtc ;&lt;BR /&gt;informat adtc date9.;&lt;BR /&gt;format adtc yymmdd10.;&lt;BR /&gt;datalines;&lt;BR /&gt;100 15JAN2010&lt;BR /&gt;100 14AUG2010&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data= have1 out = have1_sort;&lt;BR /&gt;by usubjid;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Proc Sql;&lt;BR /&gt;Create Table want_sql as select a.usubjid, adtc , epoch,&lt;BR /&gt;count, sstdtc, sendtc From have1 as a left join have as b on a.usubjid= b.usubjid where&lt;BR /&gt;sstdtc &amp;lt;= adtc &amp;lt;=sendtc order by usubjid ,adtc,count;&lt;BR /&gt;Quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc print data = want_sql;&lt;BR /&gt;title'proc sql result';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/****proc transpose method******/&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;create table _have as&lt;BR /&gt;select usubjid, epoch , sstdtc as start, sendtc as end ,count from have&lt;BR /&gt;order by usubjid, epoch,count;&lt;BR /&gt;quit;&lt;BR /&gt;proc sort data = _have out= have_s;&lt;BR /&gt;by usubjid count;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc transpose data=have_s out=s_t;&lt;BR /&gt;by usubjid count;&lt;BR /&gt;var epoch start end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc transpose data=s_t out=set_f(drop=_name_) delimiter=_;&lt;BR /&gt;by usubjid;&lt;BR /&gt;id _name_ count;&lt;BR /&gt;var col1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data se_f;&lt;BR /&gt;merge s_t (in=ina) set_f (in=inb);&lt;BR /&gt;by usubjid;&lt;BR /&gt;drop col1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data = se_f ;&lt;BR /&gt;by usubjid ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;merge have1 (in=ina) se_f(in=inf);&lt;BR /&gt;by usubjid;&lt;/P&gt;&lt;P&gt;if ina;&lt;BR /&gt;array sstdtc(3) start_1-start_3;&lt;BR /&gt;array sendtc(3) end_1-end_3;&lt;BR /&gt;array ep(3) epoch_1-epoch_3;&lt;/P&gt;&lt;P&gt;do i=1 to 3;&lt;BR /&gt;sestd=strip(sstdtc(i));&lt;BR /&gt;seend=strip(sendtc(i));&lt;BR /&gt;put adtc;&lt;/P&gt;&lt;P&gt;aestd=put(adtc,yymmdd10.);&lt;BR /&gt;format aestd yymmdd10.;&lt;BR /&gt;put sestd;&lt;BR /&gt;put aestd;&lt;BR /&gt;put seend;&lt;BR /&gt;put ep(i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if sestd &amp;lt;= aestd &amp;lt;= seend then&lt;BR /&gt;do;&lt;BR /&gt;epoch = ep(i);&lt;BR /&gt;leave;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;drop _name_ epoch_1 epoch_2 epoch_3 start_1 start_2 start_3 end_1 end_2 end_3 aestd i;&lt;BR /&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data want_transpose;&lt;BR /&gt;set want;&lt;BR /&gt;rename sestd=sstdtc&lt;BR /&gt;seend = sendtc;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data =want_transpose nodupkey ;&lt;BR /&gt;by usubjid count;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc print data=want_transpose;&lt;BR /&gt;title 'proc transpose result';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc compare base = want_sql compare= want_transpose;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 02:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-compare-between-sql-left-join-and-proc-transpose-not/m-p/771287#M30949</guid>
      <dc:creator>ng1090</dc:creator>
      <dc:date>2021-09-30T02:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: proc compare between sql left join and proc transpose not getting the same result ?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-compare-between-sql-left-join-and-proc-transpose-not/m-p/771292#M30950</link>
      <description>&lt;P&gt;Sounds like you are expecting the two different methods to produce the same output.&lt;/P&gt;
&lt;P&gt;Do you know which one is right?&lt;/P&gt;
&lt;P&gt;What is it you are trying to do?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please describe the meaning of the two input datasets and the meaning of the result you are trying to create.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 03:08:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-compare-between-sql-left-join-and-proc-transpose-not/m-p/771292#M30950</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-30T03:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: proc compare between sql left join and proc transpose not getting the same result</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-compare-between-sql-left-join-and-proc-transpose-not/m-p/771293#M30951</link>
      <description>Yes, I am trying to produce same output with 2 different approaches and&lt;BR /&gt;then comparing them using proc compare.&lt;BR /&gt;Output produced by proc Sql - left Join is correct, but using proc&lt;BR /&gt;transpose it is changing the data type in final output dataset.&lt;BR /&gt;&lt;BR /&gt;While comparing it is displaying different data types for variables with&lt;BR /&gt;Date values. Proc Sql is giving as Date while proc transpose is giving&lt;BR /&gt;String data type and format.</description>
      <pubDate>Thu, 30 Sep 2021 03:17:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-compare-between-sql-left-join-and-proc-transpose-not/m-p/771293#M30951</guid>
      <dc:creator>ng1090</dc:creator>
      <dc:date>2021-09-30T03:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: proc compare between sql left join and proc transpose not getting the same result</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-compare-between-sql-left-join-and-proc-transpose-not/m-p/771294#M30952</link>
      <description>&lt;P&gt;So the differences you see with PROC COMPARE is not the issue?&amp;nbsp; Then why did you run PROC COMPARE?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you just demonstrate your issue with PROC TRANSPOSE without all of the other baggage?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC TRANSPOSE can take multiple variables and put them into a multiple observations of a single variable.&amp;nbsp; If you transpose a mixed set of variables (at least one numeric and at least one character) then the numbers will HAVE to be converted into characters so that all of the values can be stored into the same target variable.&amp;nbsp; A single variable can only have one type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You still have not described what the input data IS nor what the output data means.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 03:22:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-compare-between-sql-left-join-and-proc-transpose-not/m-p/771294#M30952</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-30T03:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: proc compare between sql left join and proc transpose not getting the same result</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-compare-between-sql-left-join-and-proc-transpose-not/m-p/771296#M30953</link>
      <description>&lt;P&gt;Here are the input data sets&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;length epoch $10. ;&lt;BR /&gt;input usubjid sstdtc sendtc epoch $ count;&lt;BR /&gt;informat sstdtc date9. sendtc date9.;&lt;BR /&gt;format sstdtc sendtc yymmdd10.;&lt;BR /&gt;datalines;&lt;BR /&gt;100 01JAN2010 15JAN2010 Screening 1&lt;BR /&gt;100 15JAN2010 15JUL2010 Treatment 2&lt;BR /&gt;100 16JUL2010 20DEC2010 Follow-up 3&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data = have out = have_sort;&lt;BR /&gt;by usubjid count;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have1;&lt;BR /&gt;input usubjid adtc ;&lt;BR /&gt;informat adtc date9.;&lt;BR /&gt;format adtc yymmdd10.;&lt;BR /&gt;datalines;&lt;BR /&gt;100 15JAN2010&lt;BR /&gt;100 14AUG2010&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data= have1 out = have1_sort;&lt;BR /&gt;by usubjid;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;this is the proc SQL i'm using&lt;/P&gt;&lt;P&gt;Proc Sql;&lt;BR /&gt;Create Table want_sql as select a.usubjid, adtc , epoch,&lt;BR /&gt;count, sstdtc, sendtc From have1 as a left join have as b on a.usubjid= b.usubjid where&lt;BR /&gt;sstdtc &amp;lt;= adtc &amp;lt;=sendtc order by usubjid ,adtc,count;&lt;BR /&gt;Quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc print data = want_sql;&lt;BR /&gt;title'proc sql result';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;this is the result from proc SQL&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ng1090_0-1632973006487.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64242i196737A790A692D8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ng1090_0-1632973006487.png" alt="ng1090_0-1632973006487.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to get the same result with proc transpose.&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, 30 Sep 2021 03:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-compare-between-sql-left-join-and-proc-transpose-not/m-p/771296#M30953</guid>
      <dc:creator>ng1090</dc:creator>
      <dc:date>2021-09-30T03:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: proc compare between sql left join and proc transpose not getting the same result ?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-compare-between-sql-left-join-and-proc-transpose-not/m-p/771302#M30954</link>
      <description>&lt;P&gt;There is pretty much no guarantee on the order of output from Proc SQL for tied values on an "order by" much less when you make no attempt to control order. With large data sets and some environments Proc SQL will return different order from the exact same input data with the exact same code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc transpose will process values in order presented to the procedure but it may take some time to get used to the behavior.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 03:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-compare-between-sql-left-join-and-proc-transpose-not/m-p/771302#M30954</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-09-30T03:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: proc compare between sql left join and proc transpose not getting the same result</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-compare-between-sql-left-join-and-proc-transpose-not/m-p/771325#M30955</link>
      <description>&lt;P&gt;By including the character variable epoch in the VAR statement of PROC TRANSPOSE, you force the procedure to make COL1 character.&lt;/P&gt;
&lt;P&gt;But the difference in code complexity between the single SQL step and the (in comparison) enormous transpose method alone should tell you which to use.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 09:05:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-compare-between-sql-left-join-and-proc-transpose-not/m-p/771325#M30955</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-30T09:05:13Z</dc:date>
    </item>
  </channel>
</rss>

