BookmarkSubscribeRSS Feed
blackraven
Fluorite | Level 6
Hi.

I want to do what seems to be something simple. Variable v2 should make an enumeration change when v1 changes. v1 need to come out in the unsorted way it is. How do I do this?

v1 v2
a 1
a 1
a 1
c 2
c 2
b 3
1 REPLY 1
SASKiwi
PROC Star
You could try something like this:

data new;
set old;
retain last_v1;
if last_v1 ne v1 then v2 +1;
last_v1 = v1;
run;

On the first row last_v1 will not be assigned so v2 is set to 1.

On row 4, where there is a change v1 will not equal last_v1 so 1 is added to v2.

sas-innovate-2024.png

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.

 

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
  • 1 reply
  • 716 views
  • 0 likes
  • 2 in conversation