BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
vnreddy
Quartz | Level 8

Hi, Could someone help me with below :

 

data want;
input REGION $ NAME $ DATE :datetime20. DCODE $ TRAVEL;
format date datetime20.;
datalines;
EAST	LEE		01JUN2022:00:00:00	AP64389	21.09
EAST	LEE		03JUN2022:00:00:00	AP64389	15.19
EAST	SAM		05JUN2022:00:00:00	PS1234	4.14
EAST	LEE		07JUN2022:00:00:00	GP38299	2.09
WEST	DAN		07JUN2022:00:00:00	CX78934	10.07
WEST	DAN		07JUN2022:00:00:00	CX78934	8.07
WEST	DAN		07JUN2022:00:00:00	PB53468	10.07
WEST	DAN		07JUN2022:00:00:00	PB53468	10.07
SOUTH	TIM		02JUN2022:00:00:00	SU18934	52.23
;
run;

Expected output :

I need to show the total count of codes based on the user level, from above NAME LEE has to AP64389 repeated two times so the count will be 2. and the tot_travel is total of AP64389 (21.09+15.19 = 36.28) and the avg_travel will be (36.28/2 = 18.14)

and the bottom of each name i need to show the total of count, tot_travel, and the avg_travel should be total of tot_travel/total of count i.e., 38.37/3 = 12.79

 

vnreddy_0-1657539346354.png

I need the report in same format, could someone help me how can i achive this.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data want;
input REGION $ NAME $ DATE :datetime20. DCODE $ TRAVEL;
format date datetime20.;
datalines;
EAST	LEE		01JUN2022:00:00:00	AP64389	21.09
EAST	LEE		03JUN2022:00:00:00	AP64389	15.19
EAST	SAM		05JUN2022:00:00:00	PS1234	4.14
EAST	LEE		07JUN2022:00:00:00	GP38299	2.09
WEST	DAN		07JUN2022:00:00:00	CX78934	10.07
WEST	DAN		07JUN2022:00:00:00	CX78934	8.07
WEST	DAN		07JUN2022:00:00:00	PB53468	10.07
WEST	DAN		07JUN2022:00:00:00	PB53468	10.07
SOUTH	TIM		02JUN2022:00:00:00	SU18934	52.23
;
run;
proc report data=want nowd;
column  REGION  NAME DCODE n TRAVEL TRAVEL=TRAVEL1;
define REGION/group order=data;
define NAME/group;
define DCODE/group;
define n/'COUNT';
define TRAVEL/analysis sum 'TOT_TRAVEL';
define TRAVEL1/analysis mean 'AVG_TRAVEL';
compute after NAME;
REGION=' ';
endcomp;
break after NAME/summarize;
run;

Ksharp_0-1657543142292.png

 

View solution in original post

4 REPLIES 4
andreas_lds
Jade | Level 19

Why is Lee with Dcode = PS1234 ignored?

 

vnreddy
Quartz | Level 8

@andreas_lds sorry it's my bad, updated now.

PaigeMiller
Diamond | Level 26
proc summary data=have;
    class region name dcode;
    types region*name region*name*dcode;
    var travel;
    output out=want sum=tot_travel mean=avg_travel;
run;
    

From there, sorting the data will get you the layout you want.

 

proc sort data=want;
    by region name descending _type_ dcode;
run;
--
Paige Miller
Ksharp
Super User
data want;
input REGION $ NAME $ DATE :datetime20. DCODE $ TRAVEL;
format date datetime20.;
datalines;
EAST	LEE		01JUN2022:00:00:00	AP64389	21.09
EAST	LEE		03JUN2022:00:00:00	AP64389	15.19
EAST	SAM		05JUN2022:00:00:00	PS1234	4.14
EAST	LEE		07JUN2022:00:00:00	GP38299	2.09
WEST	DAN		07JUN2022:00:00:00	CX78934	10.07
WEST	DAN		07JUN2022:00:00:00	CX78934	8.07
WEST	DAN		07JUN2022:00:00:00	PB53468	10.07
WEST	DAN		07JUN2022:00:00:00	PB53468	10.07
SOUTH	TIM		02JUN2022:00:00:00	SU18934	52.23
;
run;
proc report data=want nowd;
column  REGION  NAME DCODE n TRAVEL TRAVEL=TRAVEL1;
define REGION/group order=data;
define NAME/group;
define DCODE/group;
define n/'COUNT';
define TRAVEL/analysis sum 'TOT_TRAVEL';
define TRAVEL1/analysis mean 'AVG_TRAVEL';
compute after NAME;
REGION=' ';
endcomp;
break after NAME/summarize;
run;

Ksharp_0-1657543142292.png

 

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!
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
  • 4 replies
  • 523 views
  • 4 likes
  • 4 in conversation