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

Hi! I'd like a variable that is just the sum of all 1's in a given column.

both are numeric variables

example:

 

given   want

1          4

0          4

1          4

1          4

1          4

0          4

0          4

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hello @jmmedina25  Enjoy remerge 

 

 


data have;
input given ;*  want;
cards;
1          4
0          4
1          4
1          4
1          4
0          4
0          4
;

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

 or

proc sql;
create table want as
select *,sum(given=1) as want
from have;
quit;

View solution in original post

3 REPLIES 3
Reeza
Super User

PROC MEANS

https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic.sas

There are lots of ways, choose of which to use, usually depends on what you plan to do next.

 


@jmmedina25 wrote:

Hi! I'd like a variable that is just the sum of all 1's in a given column.

both are numeric variables

example:

 

given   want

1          4

0          4

1          4

1          4

1          4

0          4

0          4


 

novinosrin
Tourmaline | Level 20

Hello @jmmedina25  Enjoy remerge 

 

 


data have;
input given ;*  want;
cards;
1          4
0          4
1          4
1          4
1          4
0          4
0          4
;

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

 or

proc sql;
create table want as
select *,sum(given=1) as want
from have;
quit;
novinosrin
Tourmaline | Level 20

The above is the same as 

proc sql;
create table want as
select *
from have a,(select sum(given) as want from have);
quit;
data want;
do until(lr);
set have end=lr;
sum+given;
end;
lr=0;
do until(lr);
set have end=lr;
output;
end;
run;

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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