RAW_DATA | ||||||||
Obs | Flag_A | Flag_B | Flag_C | Flag_D | Flag_E | Flag_F | Flag_G | N |
1 | No | 1 | ||||||
2 | Yes | 2 | ||||||
3 | No | 3 | ||||||
4 | No | 4 | ||||||
5 | Yes | 5 | ||||||
6 | No | 6 | ||||||
7 | Yes | 7 | ||||||
8 | No | 8 | ||||||
9 | Yes | 9 | ||||||
10 | No | 10 | ||||||
11 | Yes | 11 | ||||||
12 | No | 12 | ||||||
13 | Yes | 13 | ||||||
RRQUIRED: | ||||||||
Flag_A | No | 1 | ||||||
Flag_A | Yes | 2 | ||||||
Flag_B | No | 3 | ||||||
Flag_B | Yes | 0 | ||||||
Flag_c | No | 4 | ||||||
Flag_c | Yes | 5 | ||||||
Flag_d | No | 6 | ||||||
Flag_D | Yes | 7 | ||||||
Flag_E | No | 8 | ||||||
Flag_E | Yes | 9 | ||||||
Flag_F | No | 10 | ||||||
Flag_F | Yes | 11 | ||||||
Flag_G | No | 12 | ||||||
Flag_G | Yes | 13 |
Arrays would come in handy, especially if you actually have more than six variables:
data want;
set have;
array flags {6} Flag_A Flag_B Flag_C Flag_D Flag_E Flag_F;
do _n_=1 to 6;
if flags{_n_} > ' ' then do;
FlagVar = vname(flags{_n_});
Flag = flags{_n_};
end;
keep FLagVar Flag N;
run;
Is this for a report or a data set?
This is for data set and then Proc GChart.
Arrays would come in handy, especially if you actually have more than six variables:
data want;
set have;
array flags {6} Flag_A Flag_B Flag_C Flag_D Flag_E Flag_F;
do _n_=1 to 6;
if flags{_n_} > ' ' then do;
FlagVar = vname(flags{_n_});
Flag = flags{_n_};
end;
keep FLagVar Flag N;
run;
Our community "Astounding" user provided excellent solutions.
Our community "Astounding" user provided excellent and timely solutions.
@GPatel wrote:
Our community "Astounding" user provided excellent and timely solutions.
Please mark that solution as the correct answer 🙂
You should have marked @Astounding solution as correct, not mine!
Maybe @ShelleySessoms can fix this?
Thanks
All fixed! Thanks for alerting us to the incorrect mark, @Reeza. We definitely want to acknowledge the correct answer!
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 25. Read more here about why you should contribute and what is in it for you!
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.