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

Hello,

Thanks for checking!

 

My goal is to get the sum of count of 2 variables (num_id1 and num_id2)  in separate column as 'IDCounts'.

I am getting error prior computing that new column.

 

 

My output should be like this:

num_id1   num_id 2   IDcounts(Newcolumn)

2                   4                      6

4                   4                      8

 

 

proc sql;
create table test.number
as select name, count(num_id1) as count1,

count(num_id2) as count2,
sum(count(cin_id1)) as grand_sum, (Tried this way, still getting error)
sum(count1) as grand_sum1

from test.data

run;

 

 

ERROR: The SUM summary function requires a numeric argument.
ERROR: Summary functions nested in this way are not supported.
ERROR: The following columns were not found in the contributing tables: count1.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Looks like you might be confusing the SQL aggregate function SUM() with the SAS function SUM(,).

The first one takes one argument and calculates the sum across observations. The second takes two or more arguments and sums the values in the same observation.

proc sql;
create table test.number as
  select name
      , count(num_id1) as count1
      , count(num_id2) as count2
      , sum(calculated count1, calculated count2) as grand_sum
  from test.data
  group by name
  order by name
;
quit;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Looks like you might be confusing the SQL aggregate function SUM() with the SAS function SUM(,).

The first one takes one argument and calculates the sum across observations. The second takes two or more arguments and sums the values in the same observation.

proc sql;
create table test.number as
  select name
      , count(num_id1) as count1
      , count(num_id2) as count2
      , sum(calculated count1, calculated count2) as grand_sum
  from test.data
  group by name
  order by name
;
quit;
Kalai2008
Pyrite | Level 9
Thank you! It worked..

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
  • 2 replies
  • 11920 views
  • 1 like
  • 2 in conversation