Help using Base SAS procedures

Create Classes within dataset

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Create Classes within dataset

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


Accepted Solutions
Solution
‎02-17-2017 09:30 AM
Super User
Posts: 10,497

Re: Create Classes within dataset

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


All Replies
Solution
‎02-17-2017 09:30 AM
Super User
Posts: 10,497

Re: Create Classes within dataset

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.

 

New Contributor
Posts: 2

Re: Create Classes within dataset

Worked perfectly! Thanks!
Valued Guide
Posts: 797

Re: Create Classes within dataset

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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