BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tSAS1
Obsidian | Level 7
Hello everyone,
 
I have a database like that :
ID
flag
A
1
A
1
A
1
A
1
A
21
A
1
A
1
B
1
B
1
B
7
B
1
B
1
B
1
B
30
B
1
B
1
B
1
B
1
B
1
 
 and I want to sum all the 1 values of flag variable separated with different numbers it to this form:
 
1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

Your data is a picture. Make it TEXT.

 

data test;
   input id y;
   cards;
1 1
1 1
1 2
1 1
1 1
1 1
1 3
1 1
2 1
2 2
2 1
2 1
2 1
2 3
2 1
;;;;
proc summary data=test nway missing;
   by id y notsorted;
   output out=test2(where=(y eq 1)) sum(y)=sumY;
   run;
proc print;
   run;

Capture.PNG

View solution in original post

2 REPLIES 2
data_null__
Jade | Level 19

Your data is a picture. Make it TEXT.

 

data test;
   input id y;
   cards;
1 1
1 1
1 2
1 1
1 1
1 1
1 3
1 1
2 1
2 2
2 1
2 1
2 1
2 3
2 1
;;;;
proc summary data=test nway missing;
   by id y notsorted;
   output out=test2(where=(y eq 1)) sum(y)=sumY;
   run;
proc print;
   run;

Capture.PNG

tSAS1
Obsidian | Level 7
Thank you
The code works successfully

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 823 views
  • 2 likes
  • 2 in conversation