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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 6 replies
  • 807 views
  • 0 likes
  • 4 in conversation