Hi,
I have a code to count duplicated items:
data work.rank;
set work.Inbound;
by ITEM;
if first.ITEM then Rank=1;
else Rank+1;
Run;
This is great and does the job i want.
However, i'm now bringing through data from different countries so i now have a column that shows which country the items are in. In order for this code to work i have to have the data sorted by Item so that it can count. However i don't want to include different country data in the count. So if there is 1 item in GB 5 times it will rank it 1,2,3,4 and 5 etc, but when it goes to say FR and has the same Item, i want that one to start at 1.
eg:
Country | Item | Rank |
GB | 123 | 1 |
GB | 123 | 2 |
GB | 123 | 3 |
GB | 1234 | 1 |
GB | 1234 | 2 |
FR | 12 | 1 |
FR | 123 | 1 |
FR | 123 | 2 |
FR | 1234 | 1 |
The original code i had was perfect for use in 1 country but as soon as i brought through more it is failing as i tried sorting by country first and then item.
any help would be brilliant.
Apologies if what i am asking is silly.
Cheers,
M.
Sort by item and country, and then use
by item country;
and first.country for the condition in your datastep.
Or simply sort by country and item, and use
by country item;
in your original datastep with the same first. condition.
Sort by item and country, and then use
by item country;
and first.country for the condition in your datastep.
Or simply sort by country and item, and use
by country item;
in your original datastep with the same first. condition.
Why not use the proc rank function, its what its made for:
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473611.htm
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.