BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasmaverick
Obsidian | Level 7

I have a dataset below:

RegionIDCompanyGroupCount
East12345 XYZCustomer7
East45678 ABCCustomer7
East45677 IUTACustomer7
East23456 JHUYProvider9
East09876IOPUProvider9
West89765BNJKCustomer12
West76545OPOUCustomer12
West32378YUIOSupplier10
West35357IOPIProvider15
West72348RTYUProvider15

I want the output in the following format using proc report.

               Region=East

ID           Company   Group           Count

12345     XYZ         

45678     ABC         

45677     IUTA         

--------------------------------------------------------------

                              CUSTOMER     7

--------------------------------------------------------------

23456     JHUY

09876     IOPU

-------------------------------------------------------------

                              PROVIDER     9

-------------------------------------------------------------

                    Region=West

ID          Company          Group          Count    

89765     BNJK           

76545     OPOU         

---------------------------------------------------------------

                              CUSTOMER     12

---------------------------------------------------------------

I am currently using the below code which is not working out for me. Would appreciate the inputs.

proc report data=test headline headskip nowindows;

by region;

column region ID Company Group Count;

define region/noprint;

define Group/group;

break after count/summarize;

define count/group;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

How about :

data have;
input Region $     ID     Company $     Group $     Count     ;
cards;
East     12345     XYZ     Customer     7
East     45678     ABC     Customer     7
East     45677     IUTA     Customer     7
East     23456     JHUY     Provider     9
East     09876     IOPU     Provider     9
West     89765     BNJK     Customer     12
West     76545     OPOU     Customer     12
West     32378     YUIO     Supplier     10
West     35357     IOPI     Provider     15
West     72348     RTYU     Provider     15
;
run;
options missing=' ';
proc report data=have headline headskip nowindows ;
by region;
column region ID Company Group Count _Group _Count;
define region/noprint;
define id/display;
define company/display;
define Group/display order noprint;
define count/analysis mean noprint;
define _Group/computed 'Group';
define _count/computed 'count';
compute _Group/character length=20;
endcomp;
compute after group;
_Group=Group;
_count=count.mean;
endcomp;
break after group/summarize;
run;




Xia Keshan

View solution in original post

2 REPLIES 2
Ksharp
Super User

How about :

data have;
input Region $     ID     Company $     Group $     Count     ;
cards;
East     12345     XYZ     Customer     7
East     45678     ABC     Customer     7
East     45677     IUTA     Customer     7
East     23456     JHUY     Provider     9
East     09876     IOPU     Provider     9
West     89765     BNJK     Customer     12
West     76545     OPOU     Customer     12
West     32378     YUIO     Supplier     10
West     35357     IOPI     Provider     15
West     72348     RTYU     Provider     15
;
run;
options missing=' ';
proc report data=have headline headskip nowindows ;
by region;
column region ID Company Group Count _Group _Count;
define region/noprint;
define id/display;
define company/display;
define Group/display order noprint;
define count/analysis mean noprint;
define _Group/computed 'Group';
define _count/computed 'count';
compute _Group/character length=20;
endcomp;
compute after group;
_Group=Group;
_count=count.mean;
endcomp;
break after group/summarize;
run;




Xia Keshan

sasmaverick
Obsidian | Level 7

Thanks a ton Xia! Worked perfectly!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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