DATA Step, Macro, Functions and more

How to reshape data?

Accepted Solution Solved
Reply
Contributor
Posts: 69
Accepted Solution

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: 5,497

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;

View solution in original post


All Replies
Super User
Posts: 11,343

Re: How to reshape data?

Is this for a report or a data set?

Contributor
Posts: 69

Re: How to reshape data?

This is for data set and then Proc GChart.

Solution
‎06-01-2016 11:15 AM
Super User
Posts: 5,497

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: 69

Re: How to reshape data?

Posted in reply to Astounding

Our community "Astounding" user provided excellent solutions. 

Contributor
Posts: 69

Re: How to reshape data?

Posted in reply to Astounding

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

Super User
Posts: 19,770

Re: How to reshape data?


GPatel wrote:

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


Please mark that solution as the correct answer Smiley Happy

Super User
Posts: 19,770

Re: How to reshape data?

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

Maybe @ShelleySessoms can fix this? 

 

Thanks

Community Manager
Posts: 406

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: 5,497

Re: How to reshape data?

Smiley Very Happy

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 616 views
  • 4 likes
  • 5 in conversation