BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
saf_nadia
Fluorite | Level 6
Hi, I have a dataset where the last row has a total cummulative entries value. This value(1094) need to be divided by 12. Then i need to get rows of the dataset when value the cummulative column reach the multiplier value. Eg, 1094/12=91.6.. The output is to get rows when cummulative entries reach 91, 182,273,.... Example,

Name Entries Cumm_entries
Myn 70 70
Ann 85 155
Dave 24 179
Amy 39 218
Ram 82 300
Bay 9 309
.
.
.
Tom 7 1094
Since values of cumm entries of 91, 182,273 in row 2nd, 4th and 5th rows, the output that i want is as below:

Name Entries Cumm_entries
Ann 85 155
Amy 39 218
Ram 82 300

Appreciate if any of sifu here can help me.
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
proc sql noprint;
    select sum(entries)/12 into :sizing from have;
quit;
data want;
    set have;
    prev_cumm = lag(cumm_entries);
    if floor(cumm_entries/&sizing) ^= floor(prev_cumm/&sizing) then output;
run;
--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

UNTESTED CODE

 

data want;
    set have;
    prev_cumm = lag(cumm_entries);
    if floor(cumm_entries/91) ^= floor(prev_cumm/91) then output;
run;
--
Paige Miller
saf_nadia
Fluorite | Level 6
Hi, thanks for your reply. I have few datasets and each has different sizing hence total cummulative also would be different. But each dataset need to be divided by 12. How can I program to get the total cummulative value and divide by 12 for each dataset and then get the rows that have multiplier in it?
PaigeMiller
Diamond | Level 26
proc sql noprint;
    select sum(entries)/12 into :sizing from have;
quit;
data want;
    set have;
    prev_cumm = lag(cumm_entries);
    if floor(cumm_entries/&sizing) ^= floor(prev_cumm/&sizing) then output;
run;
--
Paige Miller
saf_nadia
Fluorite | Level 6
I’ve tested but the output is not like I want it to be. The output should be 12 rows only and my cumm_entries values also seem modified
PaigeMiller
Diamond | Level 26

Show us the output you get. Show us the output you want to get. Oh, yeah, also give us the complete data set you are working with.

--
Paige Miller
saf_nadia
Fluorite | Level 6
Hi,
Have tried the code. It does work for 2nd-11th row of output but nit the
first row. It takes first row of the data as the first row of output. The
output should exclude the first row but include the last row since
sizing/12. But the last row of dataset is not the output here.


sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 928 views
  • 3 likes
  • 2 in conversation