i have aa data set
data t;
name rating post;
cards;
a 2 ASE
b 3 ASE
c 4 ITA
d 5 ITA
e 2 VP
f 7 Vp
;run;
want to knw the rating of each person out of whole rating and performed the following query
proc sql;
select first_name,(calculated rating/r) from pawan.test,(select sum(rating) as r from pawan.test1);
quit;
getting error
ERROR: It appears that the CALCULATED variable rating was referenced before it was defined.
ERROR: The following columns were not found in the contributing tables: post.
ERROR: The following columns were not found as CALCULATED references in the immediate query: rating.
I suspect that what you need is not SQL but proc rank:
data have;
length name $12 rating 8 post $12;
input name rating post;
cards;
a 2 ASE
b 3 ASE
c 4 ITA
d 5 ITA
e 2 VP
f 7 Vp
;
proc rank data=have out=want ties=dense;
var rating;
ranks ratingRank;
run;
proc print data=want noobs; run;
if not, tell us what you expect as a result.
Proc sql;
Select *,rating/(select sum(rating) from t) as total_rating
From t;
Quit;
SAS SQL can accomplish this fairly easily.
proc sql;
create table want as
select *, rating/sum(rating) as pct_rating
from have;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.