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

Hello everyone,

 

I'm not sure how best to phrase my question, so I'll just show the input and desired output:

 

The input has the first observation of each class marked with a 1 in the "Set" column. The sorting of the data is obviously very important here, as I've essentially binned the observations according to a particular behaviour that we were observing, which is marked by the 1. I want for all observations until the next instance of a 1 to be in the same class.

 

Set
1
0
0
1
0
0
0
1
1
0
0

 

The desired output is as follows:

 

SetClass
11
01
01
12
02
02
02
13
14
04
04

 

Any help is much appreciated.

 

Cheers,

Sean

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Something like this should get you started:

data want;
   set have;
   retain class 0;
   class=class+set;
run;

RETAIN is the basic instruction to keep the value of a variable across interations in the data set.

 

View solution in original post

3 REPLIES 3
ballardw
Super User

Something like this should get you started:

data want;
   set have;
   retain class 0;
   class=class+set;
run;

RETAIN is the basic instruction to keep the value of a variable across interations in the data set.

 

seankortschot
Calcite | Level 5
Worked perfectly! Thanks!
mkeintz
PROC Star

Then mark the useful response as a solution to your topic question.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

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

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 2591 views
  • 2 likes
  • 3 in conversation