BookmarkSubscribeRSS Feed
AnneDee
Calcite | Level 5

Hi

 

I need help with a JMP formula.

 

I have to up count rows (1 to x) based on a value of a second column, which changes after a while. With each change the up count has to start with 1 again.

 

Value      Kit ID                 Count

2.3          00047                1
0.9          00047                2
1.8          00047                3
0.3          00264               1
5.7          00264               2
3.2          00053               1
0.1          00053                2

0.9          00053                3

8.3          00053                4 

 

I got them counted in total by using col number() or counted from 1 to the end by using Sequence(), but i cannot make the formula start couting from 1 again after Kit ID changed. 

 

Anyone who can help me out?

5 REPLIES 5
ccaulkins9
Pyrite | Level 9
AnneDee, Have you tried using proc sql in Base SAS I'm a little rusty but I bet you could find some more info around count aggregations in a SAS Community like Base SAS or ODS-something.
e-SAS regards,

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Edit:

You could probably shrink to:

data want;
  set have;
  by kitid;
  retain count;
  count=ifn(first.kitid,1,sum(count,1);
run;

 

Assuming your data is sorted:

data want;
  set have;
  by kitid;
  retain count;
  if first.kitid then count=1;
  else count=count+1;
run;

 

ccaulkins9
Pyrite | Level 9
rw9,
I stand corrected, data step is much more "elegant". :$
e-SAS regards,

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 3136 views
  • 2 likes
  • 3 in conversation