BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vidyasagar1
Obsidian | Level 7
data one;
 infile datalines;
 input Group1$ Head :$20. Reported;
 datalines;
 Adult Drink 2 
 Adult Commit 2
 Adult Medicine 1
 Adult Grains 5
 Adult Others 1
 Burglary Banks 1
 Burglary CommercialPlaces 3
 Burglary Residential 5
 Burglary Others 6
 Hurt Attack 4
 Hurt Disputes 3
 Hurt Others 7
 ;
RUN;

 
proc report data=one;
 column group1 head Reported;
 define group1 / group;
 define head / group;
run;

I have data like above and i need to get the output like below using proc report

 

Sl. No.Heads of GroupReported
1Adult 
 Commit2
 Drink2
 Grains5
 Medicine1
 Others1
 Sub Total11
2Burglary 
 Banks1
 Commercial3
 Others6
 Residentia5
 Sub Total15
3Hurt 
 Attack4
 Disputes3
 Others7
 Sub Total14
 Total40
1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
PROC Star

Welcome in the community!

 

Adding break and rbreak statements will give you sub-total and total. Generating the serial number could be done in a compute-block or by applying a self-defined format. But i have no idea how to move the value of Group1 into Head-column without modifying dataset one.

 

The format could be created with the following code:

data Group1Fmt;
   set one(keep= Group1 rename=(Group1=Start));
   by Start;
   
   length FmtName $ 32 Type $ 1;
   retain FmtName 'GroupFmt' Type 'C';
   
   if first.Start then do;
      Label + 1;      
      output;
   end;
run;

proc format cntlin=Group1Fmt;
run;

The format is applied in proc report

proc report data=one;
 column group1 head Reported;
 define group1 / group format=$groupfmt.;
 define head / group;
 
 break after group1 / summarize;
 rbreak after / summarize;
run;

View solution in original post

2 REPLIES 2
andreas_lds
PROC Star

Welcome in the community!

 

Adding break and rbreak statements will give you sub-total and total. Generating the serial number could be done in a compute-block or by applying a self-defined format. But i have no idea how to move the value of Group1 into Head-column without modifying dataset one.

 

The format could be created with the following code:

data Group1Fmt;
   set one(keep= Group1 rename=(Group1=Start));
   by Start;
   
   length FmtName $ 32 Type $ 1;
   retain FmtName 'GroupFmt' Type 'C';
   
   if first.Start then do;
      Label + 1;      
      output;
   end;
run;

proc format cntlin=Group1Fmt;
run;

The format is applied in proc report

proc report data=one;
 column group1 head Reported;
 define group1 / group format=$groupfmt.;
 define head / group;
 
 break after group1 / summarize;
 rbreak after / summarize;
run;
vidyasagar1
Obsidian | Level 7

Thank you Andrea for your reply and it is helpful and also can you please suggest how to modify data set one to get the output as required. 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 550 views
  • 1 like
  • 2 in conversation