Hi ,
I have a dataset that has gnp,cnp idnb for each of these we have Cplus and Cccare and each one has 3 p1_lmt and 3 P2_LMT values and out of that i need the first P1_LMT and 1st P2_LMT and need to generate a column Seq as shown below .
So i can pick up only seq = 1 for every gnp,cnp,idnb,type combination
gnp | cnp | idnb | Type | P1_LMT | P2_LMT | Amount | Seq |
56000 | 3200 | 520 | Cplus | 0 | 0 | 10 | 1 |
56000 | 3200 | 520 | Cplus | 1 | 3 | 20 | 2 |
56000 | 3200 | 520 | Cplus | 50 | 250 | 30 | 3 |
56000 | 3200 | 520 | Ccare | 0 | 0 | 40 | 1 |
56000 | 3200 | 520 | Ccare | 1 | 3 | 67 | 2 |
56000 | 3200 | 520 | Ccare | 50 | 250 | 90 | 3 |
345670 | 5674 | 520 | Cplus | 1 | 25 | 10 | 1 |
345670 | 5674 | 520 | Cplus | 25 | 250 | 20 | 2 |
345670 | 5674 | 520 | Cplus | 250 | 500 | 30 | 3 |
345670 | 5674 | 520 | Ccare | 1 | 25 | 40 | 1 |
345670 | 5674 | 520 | Ccare | 25 | 250 | 67 | 2 |
345670 | 5674 | 520 | Ccare | 250 | 500 | 90 | 3 |
Can anyone please help
data want;
do seq=1 by 1 until(last.type);
set have;
by gnp cnp idnb type;
output;
end;
run;
data want;
set have;
by gnp cnp idnb type;
if first.type
then seq = 1;
else seq + 1;
run;
Thank you so much for all your help . Both the solutions work . Just wanted to understand what is the difference between two solutions
data want;
do seq=1 by 1 until(last.type);
set have;
by gnp cnp idnb type;
output;
end;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.