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
Jade | Level 19

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
Jade | Level 19

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. 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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