<?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 Group and add new columns in new table. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/303218#M64374</link>
    <description>&lt;P&gt;That's not what I would expect if the program and the data are on the same machine. &amp;nbsp;But then, I haven't seen your code.&lt;/P&gt;</description>
    <pubDate>Fri, 07 Oct 2016 17:01:15 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2016-10-07T17:01:15Z</dc:date>
    <item>
      <title>How to Group and add new columns in new table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/278083#M55923</link>
      <description>&lt;P&gt;I have following table&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Input&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;S.No.&lt;/TD&gt;&lt;TD&gt;Datetime&lt;/TD&gt;&lt;TD&gt;Details&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2010/6/7 19:01&lt;/TD&gt;&lt;TD&gt;asd&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2010/6/8 4:00&lt;/TD&gt;&lt;TD&gt;dfg&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2010/6/9 0:00&lt;/TD&gt;&lt;TD&gt;dfg&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2010/6/10 0:00&lt;/TD&gt;&lt;TD&gt;gfd&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2010/6/11 0:00&lt;/TD&gt;&lt;TD&gt;gfd&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2010/6/12 0:00&lt;/TD&gt;&lt;TD&gt;gfd&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2010/6/13 0:00&lt;/TD&gt;&lt;TD&gt;abc&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2010/6/14 0:00&lt;/TD&gt;&lt;TD&gt;abc&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2010/6/15 0:00&lt;/TD&gt;&lt;TD&gt;def&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I am trying to get the following output&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;output&lt;/TD&gt;&lt;TD&gt;TimeDifference 1&lt;/TD&gt;&lt;TD&gt;TimeDifference 2&lt;/TD&gt;&lt;TD&gt;Detail 1&lt;/TD&gt;&lt;TD&gt;Detail 2&lt;/TD&gt;&lt;TD&gt;Detail 3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0.374305556&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;asd&lt;/TD&gt;&lt;TD&gt;dfg&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;dfg&lt;/TD&gt;&lt;TD&gt;gfd&lt;/TD&gt;&lt;TD&gt;gfd&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;gfd&lt;/TD&gt;&lt;TD&gt;abc&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;abc&lt;/TD&gt;&lt;TD&gt;def&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 am using SAS Base 9.4. Till now I have tried Proc SQL, GroupBy and Proc Tabulate but its not working. Although I have not reached the stage to calculate time difference but I am thinking of using INTCK for the same.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If somebody can think of any approach, please share. waiting for somebody to rescue me from this situation.&lt;/P&gt;&lt;P&gt;Thanks in advance !&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2016 02:33:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/278083#M55923</guid>
      <dc:creator>deega</dc:creator>
      <dc:date>2016-06-17T02:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group and add new columns in new table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/278091#M55926</link>
      <description>&lt;P&gt;INTCK is not meant to return fractional time interval counts. You could do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data td;
input SNo dt &amp;amp; :anydtdtm.	Details $;
format dt datetime.;
datalines;
1	2010/6/7 19:01  asd
1	2010/6/8 4:00  dfg
2	2010/6/9 0:00  dfg
2	2010/6/10 0:00  gfd
2	2010/6/11 0:00  gfd
3	2010/6/12 0:00  gfd
3	2010/6/13 0:00  abc
4	2010/6/14 0:00  abc
4	2010/6/15 0:00  def
;

proc sql;
select max(n), max(n)-1 into :nDt trimmed, :nDt1 trimmed
from (select count(*) as n from td group by SNo);
quit;

data want;
array detail_{&amp;amp;nDt} $8;
array TimeDifference_{&amp;amp;nDt1};
do i = 1 by 1 until(last.SNo);
    set td; by SNo;
    detail_{i} = details;
    if i &amp;gt; 1 then timeDifference_{i-1} = (dt - dt1) / '24:00:00't;
    dt1 = dt;
    end;
drop i dt dt1 details;
run;

proc print; run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Jun 2016 03:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/278091#M55926</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-17T03:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group and add new columns in new table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/278094#M55927</link>
      <description>&lt;P&gt;The simplest way is IDGROUP. If you have big table ,Try MERGE Skill proposed by me,Arthur.T,Matt :&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings15/2785-2015.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings15/2785-2015.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input No	Datetime &amp;amp; anydtdtm.	Details $;
format Datetime datetime20.;
cards;
1	2010/6/7 19:01	asd
1	2010/6/8 4:00	dfg
2	2010/6/9 0:00	dfg
2	2010/6/10 0:00	gfd
2	2010/6/11 0:00	gfd
3	2010/6/12 0:00	gfd
3	2010/6/13 0:00	abc
4	2010/6/14 0:00	abc
4	2010/6/15 0:00	def
;
run;

data have;
 merge have have(firstobs=2 keep=No Datetime 
 rename=(No=_No Datetime=_Datetime));
 if No=_No then dif=divide(_Datetime-Datetime,'24:00:00't);
 drop _:;
run;
proc sql noprint;
select max(n) into : n separated by ' '
 from (select count(*) as n from have group by No);
quit;
proc summary data=have;
by No;
output out=want(drop=_: dif_&amp;amp;n) idgroup(out[&amp;amp;n] (dif Details)=);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Jun 2016 03:28:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/278094#M55927</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-17T03:28:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group and add new columns in new table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/279881#M56467</link>
      <description>&lt;P&gt;Thanks for your prompt reply the other day. Now in the same problem I am facing a new issue. Actually I have big data in CSV format. When I import the data through SAS'S import wizard or proc import I get the dates in text format. Could you advise anything to get it in dates format ?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 00:37:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/279881#M56467</guid>
      <dc:creator>deega</dc:creator>
      <dc:date>2016-06-24T00:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group and add new columns in new table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/279882#M56468</link>
      <description>&lt;P&gt;Copy the code generated by PROC IMPORT from LOG and Paste it into programm&amp;nbsp;editor, Change that date variable's informat and see what happen ?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 00:56:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/279882#M56468</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-24T00:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group and add new columns in new table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/279888#M56473</link>
      <description>&lt;P&gt;Thank you so much for the suggestion but I deleted time from my datetime field in CSV file, after which I was able to import it as date. Since, now I dont have that old input so I can not try this option right now, may be some other time.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 02:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/279888#M56473</guid>
      <dc:creator>deega</dc:creator>
      <dc:date>2016-06-24T02:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group and add new columns in new table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/279892#M56475</link>
      <description>&lt;P&gt;Good news. Here are two choices:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Try some other option.&lt;/P&gt;
&lt;P&gt;proc import .....;&lt;BR /&gt;scantime=yes;&lt;BR /&gt;usedate=yes;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2)Once import into SAS, use data step to transform it.&lt;/P&gt;
&lt;P&gt;want_date=input(str_date,anydtdte.);&lt;/P&gt;
&lt;P&gt;format want_date date9.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 02:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/279892#M56475</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-24T02:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group and add new columns in new table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/303089#M64342</link>
      <description>@PG Stats&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/14779"&gt;@PG&lt;/a&gt; Stats&lt;BR /&gt;Thanks for this program.&lt;BR /&gt;Could you please tell the use/reason of using {&amp;amp;nDt} while defining arrays. In the basics of arrays all I understood is that we need to give the number of elements...</description>
      <pubDate>Fri, 07 Oct 2016 03:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/303089#M64342</guid>
      <dc:creator>deega</dc:creator>
      <dc:date>2016-10-07T03:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group and add new columns in new table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/303093#M64344</link>
      <description>&lt;P&gt;The SQL step defines two macro variables nDt and nDt1 that hold the maximum number of observations in a SNo group and that same number minus one, respectively.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These macro values are used in the data step as array dimensions where &amp;amp;nDt and &amp;amp;nDt1 are mentioned.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2016 03:23:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/303093#M64344</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-10-07T03:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group and add new columns in new table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/303101#M64347</link>
      <description>@PG Stats&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/14779"&gt;@PG&lt;/a&gt; Stats&lt;BR /&gt;Thanks for the prompt reply.&lt;BR /&gt;I have written a program based on your program where I am not calculating Time Difference also. My Data set is around 15000000 records and program is running from last 2 hours, normally does it take this much time ?</description>
      <pubDate>Fri, 07 Oct 2016 04:56:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/303101#M64347</guid>
      <dc:creator>deega</dc:creator>
      <dc:date>2016-10-07T04:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group and add new columns in new table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/303218#M64374</link>
      <description>&lt;P&gt;That's not what I would expect if the program and the data are on the same machine. &amp;nbsp;But then, I haven't seen your code.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2016 17:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Group-and-add-new-columns-in-new-table/m-p/303218#M64374</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-10-07T17:01:15Z</dc:date>
    </item>
  </channel>
</rss>

