Folks,
I'm having an issue with something at the moment which I'd be grateful for some assistance on.
I've a dataset at the moment which has a number of 0 for variable occurrence.
What I would like to do is change where there is a 0 to 1 and subsequently change the 1 to 2 and so on. Below gives a better idea.
Data in current format;
ID | Occurrence | Value |
63 | 0 | 45 |
63 | 1 | 65 |
63 | 2 | 98 |
22 | 1 | 100 |
23 | 1 | 125 |
24 | 1 | 130 |
25 | 1 | 130 |
45 | 1 | 96 |
45 | 2 | 88 |
45 | 3 | 44 |
What I would like to occur;
ID | Occurrence | Value |
63 | 1 | 45 |
63 | 2 | 65 |
63 | 3 | 98 |
22 | 1 | 100 |
23 | 1 | 125 |
24 | 1 | 130 |
25 | 1 | 130 |
45 | 1 | 96 |
45 | 2 | 88 |
45 | 3 | 44 |
If there is an instance of occurrence=0, will it always be for the first observation for an ID?
Here's an approach that makes a reasonable guess about how to handle that question:
data want;
set have;
by ID;
if first.ID then increment=0;
retain increment;
if occurrence=0 then increment=1;
occurrence = occurrence + increment;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.