Help using Base SAS procedures

Create a time column

Reply
New Contributor
Posts: 3

Create a time column

Hi!

One question =) I have imported a data set in SAS. But now i want to insert a new column. I want this column to be about time. I want this column to be the first one. Lets say it start at 01/04/1997 12:00:00 and i want it to end at a specific date feks 03/07/1998 13:45:42, the freqency is per second... How can i code this ?i want to column to be indempendt of the data set =)

Thx in advance =)

Respected Advisor
Posts: 3,156

Re: Create a time column

Posted in reply to Magaarnico

Would this be what you are after:

data want;

  do _n_=0 by 1 until (last);

  set have end=last;

format time datetime22.;

if time < input('03/07/1998 13:45:42',anydtdtm21.) then time=intnx('second',input('01/04/1997 12:00:00',anydtdtm21.), _n_);

output;

  end;

  if last then do;

  call symputx('time',time);

  call missing (of _all_);

  do _n_=1 by 1 while (time < input('03/07/1998 13:45:42',anydtdtm21.));

time=intnx('second',symget('time'), _n_);

output;

end;

  end;

  stop;

  run;

Haikuo

New Contributor
Posts: 3

Re: Create a time column

Posted in reply to Magaarnico

To be honest that is way to complicated for me to understand :smileysilly:

Let me make an ex for you =)

Example 1 (Orginaldata set):

Time                              Bid                         Ask

1/1/2013 12:00:00          1                              1

1/1/2013 12:00:02          3                              3

1/1/2013 12:00:06          1                              2

1/1/2013 12:00:20          5                              4

Example 2 (What i want):

Time 2                            Time                              Bid                         Ask

1/1/2013 12:00:00          1/1/2013 12:00:00          1                              1

1/1/2013 12:00:01          1/1/2013 12:00:02          3                              3

1/1/2013 12:00:02          1/1/2013 12:00:06          1                              2

1/1/2013 12:00:03          1/1/2013 12:00:20          5                              4

1/1/2013 12:00:04

1/1/2013 12:00:05

.

.

.

1/1/2013 12:00:20

Hope you understand that i am very new to SAS =)

Thx Hai Kuo

Super User
Posts: 10,020

Re: Create a time column

Posted in reply to Magaarnico

OK.

data have;
input Time  & anydtdtm20.                           Bid                         Ask     ;
format time datetime.;
cards;
1/1/2013 12:00:00          1                              1
1/1/2013 12:00:02          3                              3
1/1/2013 12:00:06          1                              2
1/1/2013 12:00:20          5                              4
;
run;
proc summary data=have;
var time;
output out=m max=_max min=_min;
run;
data temp;
 set m;
 do time2=_min to _max;
  output;
 end;
 format time2 datetime.;
 keep time2;
run;
data want;
 merge temp have;
run;

Ksharp

Ask a Question
Discussion stats
  • 3 replies
  • 229 views
  • 0 likes
  • 3 in conversation