BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MattehWoo
Calcite | Level 5

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:

 

CountryItemRank
GB1231
GB1232
GB1233
GB12341
GB12342
FR121
FR1231
FR1232
FR12341

 

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2068 views
  • 0 likes
  • 3 in conversation