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

I want to give the Order/ranking to my data set TAXDEPT (output in Rank col.) as shown below using PROC SQL. 

My source data set is in below form now:

SiteID is already in sorted form.

where ever SiteTax == allTax, i have to give ranks like 1,2,3,...

where ever SiteTax != allTax, i have to give sub-ranks like 3.1, 3.2, ....4.1, 4.2, ....

like for SiteID 211 below i need like; 4.1, 4.2, 4.3

TAXDEPT:

CountrySiteIDSiteTaxRank
All CountryallSiteallTax1
AustriaallSiteallTax2
Austria32allTax3
Austria32a13.1
Austria211allTax4
Austria211a24.1
Austria211a34.2
Austria211a94.3
Austria330allTax5
Austria330b25.1
Austria330b35.2
Austria330b15.3
Austria330c25.4
CanadaallSiteallTax6
Canada211allTax7
Canada211q17.1
Canada211q37.2
Canada211q27.3
Canada579allTax8
Canada579 8.1
Canada579 8.2
Canada579 8.3
Canada666allTax9
Canada666 9.1
1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16
Could you please mark it as answered so it can help others across while searching.
Thanks,
Jag

View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

please try the below code

 

data have;
input Country$ SiteID$ SiteTax$ ;
cards;
AllCountry allSite allTax
Austria allSite allTax
Austria 32 allTax
Austria 32 a1
Austria 211 allTax
Austria 211 a2
Austria 211 a3
Austria 211 a9
Austria 330 allTax
Austria 330 b2
Austria 330 b3
Austria 330 b1
Austria 330 c2
Canada allSite allTax
Canada 211 allTax
Canada 211 q1
Canada 211 q3
Canada 211 q2
Canada 579 allTax
Canada 579 .
Canada 579 .
Canada 579 .
Canada 666 allTax
Canada 666 .
;

data want;
set have;
by country siteid notsorted;
retain rank1 rank2;
if SiteTax eq 'allTax' then do;
if first.siteid then rank1+1;
if first.siteid then rank2=.;
end;
if SiteTax ne 'allTax' then rank2+0.1;
rank=sum(rank1,rank2);
drop rank1 rank2;
run;
Thanks,
Jag
mesujit
Calcite | Level 5

Thanks Jag, the code helped me a lot. 

Jagadishkatam
Amethyst | Level 16
Could you please mark it as answered so it can help others across while searching.
Thanks,
Jag

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 623 views
  • 1 like
  • 2 in conversation