BookmarkSubscribeRSS Feed
azhar7860
Obsidian | Level 7

hi

 

i have two categorical variables and i want to stack Y under X   like it seen in my attached reference report.

 

Your input will be appreciated. Thanks kindly!!!

 

 

                    X                                                                                                     Y

 

APPLICATION SITE DISORDERS                                                          injection  site pain

APPLICATION SITE DISORDERS                                                        injection site reaction

AUTONOMIC NERVOUS SYSTEM DISORDERS                                  flushing

BODY AS A WHOLE - GENERAL DISORDERS                                      ACCIDENTAL INJURY

BODY AS A WHOLE - GENERAL DISORDERS                                       ALLERGIC REACTION

BODY AS A WHOLE - GENERAL DISORDERS                                     CHEST PAIN

BODY AS A WHOLE - GENERAL DISORDERS                                    FATIGUE

BODY AS A WHOLE - GENERAL DISORDERS                                    FEVER

BODY AS A WHOLE - GENERAL DISORDERS                                  O EDEMA DEPENDENT

BODY AS A WHOLE - GENERAL DISORDERS                                O EDEMA LEGS

BODY AS A WHOLE - GENERAL DISORDERS                                PAIN

BODY AS A WHOLE - GENERAL DISORDERS                               RIGORS

2 REPLIES 2
hashman
Ammonite | Level 13

@azhar7860:

Sort by X Y, e.g.:

proc sort data = have out = stacked ;
  by X Y ;
run ;

To generate the report a la in your Word doc, you'll need to process the sorted data set STACKED using some other SAS tool relying on BY processing, such as the DATA step, the REPORT procedure, etc. For example, using the DATA step (I'm, making some formatting assumptions here):

data have ;                                                 
  input @1 X $36. @38 Y $23. ;                              
  cards ;                                                   
body as a whole - general disorders  o edema legs           
autonomic nervous system disorders   flushing               
body as a whole - general disorders  accidental injury      
body as a whole - general disorders  allergic reaction      
body as a whole - general disorders  chest pain             
application site disorders           injection site reaction
body as a whole - general disorders  fatigue                
body as a whole - general disorders  fever                  
body as a whole - general disorders  o edema dependent      
body as a whole - general disorders  pain                   
application site disorders           injection  site pain   
body as a whole - general disorders  rigors                 
;                                                           
run ;                                                       
                                                            
proc sort data = have out = stacked ;                       
  by X Y ;                                                  
run ;                                                       
                                                            
data _null_ ;                                               
  file print ;                                              
  set stacked (in = inX) stacked ;                               
  by X ;                                                    
  if first.X and inX then put X ;                          
  else put @ 5 Y ;                                          
run ;                                                       

Kind regards

Paul D. 

azhar7860
Obsidian | Level 7

Thanks paul. Its working fine with the data.

 

I  got the counts and the %(row) for both the variables in a separate data-sets, but unable to  stack the X (Preferred term) variable data-set  under the Y(System organ class) variable data-set e like it shows in my attached report.docx.

 

Your input will be appreciated!!!

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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