BookmarkSubscribeRSS Feed
HDSimo
Calcite | Level 5
Hello,
with Proc SQL is possible to have the SUM of distinct values of a specific variable. I need an option in this Proc that sum values of a variable referring to different values of another variable. Another way could be the proc sort nodupkey and then the proc freq.

Thank you

Simone
4 REPLIES 4
Peter_C
Rhodochrosite | Level 12
when selecting the set of distinct values, or when using the nodupkeys option of proc sort, how do you decide which row to keep or which rows to drop?

I would be concerned that neither method defines which of "the top equal salesmen" (for example) would be chosen to be included on the input to your final summary.
HDSimo
Calcite | Level 5
Hi Peter,
each row that i drop has the same values of the row that I keep. Let me show you a situation similar to my database:
variable ID identify a person
variable X specify a weight

In the database there are a lot of duplicated record, It's not important wich rows i've deleted. I need to calculate the sum of x but i can't use X as distinct values option because identical values of X are linked to different ID.

Thank you

Simone
Olivier
Pyrite | Level 9
Hi Simone.
Maybe a subquery would help :
[pre]PROC SQL ;
SELECT SUM(x) FROM (
SELECT DISTINCT id, x FROM myData
);
QUIT ;[/pre]
This is very similar to executing a PROC SORT with the NODUPRECS option prior to summing.
Hope this helps.
Olivier Message was edited by: Olivier
HDSimo
Calcite | Level 5
mmm... simple!
Thank you very much Olivier!

Simone

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 13349 views
  • 0 likes
  • 3 in conversation