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

Have:

 

idv1v2v3v4v5
100.1110.1
10 200.1
15 200.1
110 200.1
115 200.1
120 200.1
125 200.1
130 200.1
100.1110.2
10 200.2
15 200.2
110 200.2
115 200.2
120 200.2
125 200.2
130 200.2

 

want:

 

idv1v2v3v4v5count
100.1110.11
10 200.11
15 200.11
110 200.11
115 200.11
120 200.11
125 200.11
130 200.11
100.1110.22
10 200.22
15 200.22
110 200.22
115 200.22
120 200.22
125 200.22
130 200.22

 

I am trying to get an enumeration variable (count) which indicates number of different v5 groups by ID.

 

Please help me to derive count variable.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
7 REPLIES 7
Reeza
Super User

You need clear rules on where to restart/increment your counts. Based on sample data this could work, but it depends on how closely it matxhes your real data. 

 

Data want;

set have;

by id v1;

Retain count 0;

if v1=0 and v2=0.1 then count+1;

run;

 

ari
Quartz | Level 8 ari
Quartz | Level 8
Thanks Reeza
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

data want;
  set have;
  by id;
  retain count;
  if _n_=1 then count=0;
  if first.id then count=count+1;
run;
ari
Quartz | Level 8 ari
Quartz | Level 8

HI RW9,

 

this code gives the enumeration for the id but doesnt give the enumeration for the variable 'V5' 

ari
Quartz | Level 8 ari
Quartz | Level 8

Thanks RW9

Kurt_Bremser
Super User
proc sort data=have;
by id v5;
run;
/* just to be sure */

data want;
set have;
by id v5;
retain count;
if first.id then count = 0;
if first.v5 then count + 1;
run;
ari
Quartz | Level 8 ari
Quartz | Level 8

Thanks Kurt. 

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 7 replies
  • 6467 views
  • 2 likes
  • 4 in conversation