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

 

Hi,

i have a sequence of observations as follows

0

1

2

3

4

24

25

26

 

I need to convert the continuous sequence into variables as below

 

var1 var2   var3    var4

0       4        24       26

 

i.e whenever there is a break in sequence, i need to capture min and max of previous sequence and store it in variable.

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

do you want a production code or fun solution. if former,

how many records do you estimate to have?

what would be array size aka horizontal 

 

data have;
input n;
cards;
0
1
2
3
4
24
25
26
;
/*fun solution*/
data t;
set have;
if dif(n) ne 1 then k+1;
run;
data t1;
set t;
by k;
if first.k or last.k;
run;
proc transpose data=t1 out=want;
var n;
run;



View solution in original post

1 REPLY 1
novinosrin
Tourmaline | Level 20

do you want a production code or fun solution. if former,

how many records do you estimate to have?

what would be array size aka horizontal 

 

data have;
input n;
cards;
0
1
2
3
4
24
25
26
;
/*fun solution*/
data t;
set have;
if dif(n) ne 1 then k+1;
run;
data t1;
set t;
by k;
if first.k or last.k;
run;
proc transpose data=t1 out=want;
var n;
run;



hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 717 views
  • 1 like
  • 2 in conversation