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

data WORK.HAVE;
infile datalines dsd truncover;
input RIC:$6. year:BEST4. CGscore:BEST20. eps:BEST10.;
format year BEST4. CGscore BEST20. eps BEST10.;
datalines;
AAM.HM 2013 67.63 141
AAM.HM 2014 70.17 192
AAM.HM 2014 70.17 26
AAM.HM 2015 67.8 30
AAM.HM 2016 67.8 43
ABT.HM 2013 79.15 1331
ABT.HM 2013 79.15 1269
ABT.HM 2014 78.81 1959
ABT.HM 2014 78.81 1787
ABT.HM 2014 78.81 1768
ABT.HM 2015 77.12 1381
ABT.HM 2016 76.61 1083
ACL.HM 2014 72.54 98
ACL.HM 2014 72.54 289
ACL.HM 2016 74.92 264
ACL.HM 2016 74.92 40
ACL.HM 2016 74.92 375
AGF.HM 2013 70.85 607
AGF.HM 2013 70.85 492
AGF.HM 2014 64.41 -516
;;;;

 

Hello,

I have the dataset as above, and want to know how many RIC there are by placing a same tag (number or character) within a group of RIC, created in a new column. Simply I want to add another column counting 1 for all AAM.HM of column RIC, and 2 for all ABT.HM of RIC, 3 for all ACL.HM, and so on. Please help.

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data WORK.HAVE;
infile datalines  truncover;
input RIC:$6. year CGscore eps;
format year BEST4. CGscore BEST20. eps BEST10.;
datalines;
AAM.HM 2013 67.63 141
AAM.HM 2014 70.17 192
AAM.HM 2014 70.17 26
AAM.HM 2015 67.8 30
AAM.HM 2016 67.8 43
ABT.HM 2013 79.15 1331
ABT.HM 2013 79.15 1269
ABT.HM 2014 78.81 1959
ABT.HM 2014 78.81 1787
ABT.HM 2014 78.81 1768
ABT.HM 2015 77.12 1381
ABT.HM 2016 76.61 1083
ACL.HM 2014 72.54 98
ACL.HM 2014 72.54 289
ACL.HM 2016 74.92 264
ACL.HM 2016 74.92 40
ACL.HM 2016 74.92 375
AGF.HM 2013 70.85 607
AGF.HM 2013 70.85 492
AGF.HM 2014 64.41 -516
;;;;

 data want;
 set have;
 by ric ;
 if first.ric then c+1;
 run;

View solution in original post

5 REPLIES 5
r_behata
Barite | Level 11
It would be more helpful if you could show how your output should look like.
novinosrin
Tourmaline | Level 20
data WORK.HAVE;
infile datalines  truncover;
input RIC:$6. year CGscore eps;
format year BEST4. CGscore BEST20. eps BEST10.;
datalines;
AAM.HM 2013 67.63 141
AAM.HM 2014 70.17 192
AAM.HM 2014 70.17 26
AAM.HM 2015 67.8 30
AAM.HM 2016 67.8 43
ABT.HM 2013 79.15 1331
ABT.HM 2013 79.15 1269
ABT.HM 2014 78.81 1959
ABT.HM 2014 78.81 1787
ABT.HM 2014 78.81 1768
ABT.HM 2015 77.12 1381
ABT.HM 2016 76.61 1083
ACL.HM 2014 72.54 98
ACL.HM 2014 72.54 289
ACL.HM 2016 74.92 264
ACL.HM 2016 74.92 40
ACL.HM 2016 74.92 375
AGF.HM 2013 70.85 607
AGF.HM 2013 70.85 492
AGF.HM 2014 64.41 -516
;;;;

 data want;
 set have;
 by ric ;
 if first.ric then c+1;
 run;
PhuongNguyen
Obsidian | Level 7

It works. Thank you @novinosrin

PhuongNguyen
Obsidian | Level 7

Hi, and now I sort the dataset by CGscore. And also want to add another column, counting 1 for all same first RICs whichever come first after the sorting, and 2 for all next same RICs,............. Can you help @novinosrin @r_behata ? Thank you.

PhuongNguyen
Obsidian | Level 7

Sorry, sort the dataset by CGscore then by year.

 

Proc sort have;

by CGscore year;

run;

 

 

Thank you

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 820 views
  • 0 likes
  • 3 in conversation