BookmarkSubscribeRSS Feed
pawandh
Fluorite | Level 6

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.

4 REPLIES 4
PGStats
Opal | Level 21

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.

 

PG
pawandh
Fluorite | Level 6
i want that for "a" total_rating is "2/sum(rating)"
and for "b" is "3/sum(rating)" like so on
stat_sas
Ammonite | Level 13

Proc sql;

Select *,rating/(select sum(rating) from t) as total_rating

From t;

Quit;

Reeza
Super User

SAS SQL can accomplish this fairly easily.

 

 

proc sql;
create table want as
select *, rating/sum(rating) as pct_rating
from have;
quit;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 1259 views
  • 0 likes
  • 4 in conversation