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

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

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!

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.

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
  • 3 replies
  • 1659 views
  • 2 likes
  • 3 in conversation