I previosly made a programme that sorts a large group of data into 10 equal parts , weighted by theyre values for feild A .
I have been trying to recreate it so that it works for any amount of equal parts .
here is my code for sorting the groups .
/*setting = 10 as an example*/
%LET n = 10;
data Weighted ;
set OGDATA;
i=1;
%LET GroupNo=&i;
Format Group $10.;
Do while (i<&n);
if Cumulative_A < (((i-1)/&n)*(Total_A))Then Group = "Group &GroupNo";
put i=;
keep Total_A Cumulative_A Group A ;
i+1;
end;
output;
Run;
proc summary data=Weighted ;
by Group ;
var Total_A ;
output out=SummaryBand sum= ;
run;
run ;
PROBLEMS :
code doesnt split the data correctly , it only gives G
What does you log say? When it sees the statement
%let groupno=&I;
doesn't SAs object saying "WARNING: Apparent symbolic reference I not resolved.".
Apparently (you haven't provided any sample input data) you have incoming data obs with variables TOTAL_A and CUMULATIVE_A. And you merely want to assign a group number to the obs based on the ratio of CUMULATIVE_A/TOTAL_A. categorizing into &N equal-size ranges.
Assuming that CUMULATIVE_A always more than zero, but never more than TOTAL_A then you have a very straightforward task:
%let N=10;
data weighted;
set OGDATA;
groupno = ceil(cumulative_a/(total_a/&N));
run;
Have you already tried if Proc Rank could do the job for you?
%LET n = 10;
data have;
length a b 8;
do b=1 to 100;
a=ceil(ranuni(1)*100);
output;
end;
stop;
run;
proc rank data=have out=want groups=&n;
ranks group;
var a;
run;
proc print data=want;
run;
What does you log say? When it sees the statement
%let groupno=&I;
doesn't SAs object saying "WARNING: Apparent symbolic reference I not resolved.".
Apparently (you haven't provided any sample input data) you have incoming data obs with variables TOTAL_A and CUMULATIVE_A. And you merely want to assign a group number to the obs based on the ratio of CUMULATIVE_A/TOTAL_A. categorizing into &N equal-size ranges.
Assuming that CUMULATIVE_A always more than zero, but never more than TOTAL_A then you have a very straightforward task:
%let N=10;
data weighted;
set OGDATA;
groupno = ceil(cumulative_a/(total_a/&N));
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.