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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 849 views
  • 2 likes
  • 2 in conversation