BookmarkSubscribeRSS Feed
Magaarnico
Calcite | Level 5

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 😃

3 REPLIES 3
Haikuo
Onyx | Level 15

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

Magaarnico
Calcite | Level 5

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

Ksharp
Super User

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 854 views
  • 0 likes
  • 3 in conversation