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!
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
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
Thanks Haikuo. That did it!
I prefer to ODS.
ods _all_ close; ods output sql_results=want; proc sql number; select * from sashelp.class; quit; ods listing;
Ksharp
Hi Ksharp,
what is the advantage to use ODS?
Thanks - Linlin
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
Thank you Haikuo. - Linlin
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.