BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JKCho
Pyrite | Level 9
data credit1;
set credit;
format datadate year.;
rename datadate = year;
run;

proc sql;
create table credtY as 
 select cusip, year, mean(rating) as ratingY 
  from credit1
   group by cusip, year;
   quit;

 

1.PNG

Hi! 

 

There is no error or warning sign on the above coding... So I think the code itself works but I need sth else to get what I want.

I ran the code to get yearly average ratings(ratingY) for each frim of each year.

 

However, what I get is the same monthly ratings as the previous data file is.

I changed YYMMDD date to Year and use the code. 

 

Assuming the reason why I couldn't obtain the desired outcome is 1) many duplicates or 2) Year is not really a year but YYMMDD... 

To resolve this issue, I used "nodupkey" to delete duplicates but failed to delete them at all. 

 

I would like to ask how can I can yearly average of each firm when I have seemingly duplicate Years BUT possibly YYMMDD.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
SQL doesn't use the formatted value when aggregating, it uses the underlying values. However if you use PROC MEANS or any other PROC it will use the formatted values.

View solution in original post

5 REPLIES 5
Reeza
Super User
SQL doesn't use the formatted value when aggregating, it uses the underlying values. However if you use PROC MEANS or any other PROC it will use the formatted values.
JKCho
Pyrite | Level 9

Yeah... I passed the first hurdle. But... if my YEARS are based on underlying values, how can I merge later? I need to use YEAR to match... Can I use input() statement to convert my YEAR to a PURE year?

 

If not... is there any ways to use this YEAR with underlying values for matching with normal pure years?

Reeza
Super User
If you're joining in SQL you can actually join with a function.

select *
from x
left join y
on year(x.date) = year(y.date)
JKCho
Pyrite | Level 9
Thank you Reeza,
This is good! I will apply this code now and later!
JKCho
Pyrite | Level 9
Thank you Reeza!!!
I rather use proc means so!

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!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 771 views
  • 2 likes
  • 2 in conversation