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-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 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
  • 1670 views
  • 2 likes
  • 3 in conversation