BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
teg_76
Calcite | Level 5

Hi,

I have a data set:

LEVEL

4

5

23

64

3

4

I Need:

TIME     LEVEL

1          4

2          5

3          23

4          64

5          3

6          4

How do i read in the "time" variable that iterates by one with each "level" observation?

Thanks in Advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

There will be many ways to do that, the simplest way that I can think of:

/*data step*/

data have;

input LEVEL;

cards;

4

5

23

64

3

4

;

data want;

time=_n_;

set have;

run;

/*Proc SQL*/

proc sql;

select monotonic() as time, * from have;

quit;

Haikuo

View solution in original post

6 REPLIES 6
Haikuo
Onyx | Level 15

There will be many ways to do that, the simplest way that I can think of:

/*data step*/

data have;

input LEVEL;

cards;

4

5

23

64

3

4

;

data want;

time=_n_;

set have;

run;

/*Proc SQL*/

proc sql;

select monotonic() as time, * from have;

quit;

Haikuo

teg_76
Calcite | Level 5

Thanks Haikuo.  That did it!

Ksharp
Super User

I prefer to ODS.

ods _all_ close;
ods output sql_results=want;
proc sql number;
select * from sashelp.class;
quit;
ods listing;

Ksharp

Linlin
Lapis Lazuli | Level 10

Hi Ksharp,

what is the advantage to use ODS?

Thanks - Linlin

Haikuo
Onyx | Level 15

Linlin,

I think what Ksharp mean is that he prefer ODS to monotonic(), not data step. This has be discussed before, and Ksharp was involved. The main reason is that monotonic() is not officially supported by SAS.

Haikuo

Linlin
Lapis Lazuli | Level 10

Thank you Haikuo.  - Linlin

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1642 views
  • 0 likes
  • 4 in conversation