Solved
Contributor
Posts: 71

# How to reshape data?

 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

Accepted Solutions
Solution
‎06-01-2016 11:15 AM
Super User
Posts: 6,774

## Re: How to reshape data?

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;

All Replies
Super User
Posts: 13,542

## Re: How to reshape data?

Is this for a report or a data set?

Contributor
Posts: 71

## Re: How to reshape data?

This is for data set and then Proc GChart.

Solution
‎06-01-2016 11:15 AM
Super User
Posts: 6,774

## Re: How to reshape data?

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;

Contributor
Posts: 71

## Re: How to reshape data?

Our community "Astounding" user provided excellent solutions.

Contributor
Posts: 71

## Re: How to reshape data?

Our community "Astounding" user provided excellent and timely solutions.

Super User
Posts: 23,724

## Re: How to reshape data?

GPatel wrote:

Our community "Astounding" user provided excellent and timely solutions.

Super User
Posts: 23,724

## Re: How to reshape data?

You should have marked @Astounding solution as correct, not mine!

Maybe @ShelleySessoms can fix this?

Thanks

Community Manager
Posts: 596

## Re: How to reshape data?

All fixed! Thanks for alerting us to the incorrect mark, @Reeza. We definitely want to acknowledge the correct answer!

Super User
Posts: 6,774

## Re: How to reshape data?

🔒 This topic is solved and locked.