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

Hello,

I have a input file(have.xlsx) that has ID by date. I am looking to produce summary report by date that has count of ID by different market groups(PHL,NUC,MKT,MRC,DRA). I need help with generating the desired output(results.xlsx) with totals at the end. I also want to output the data by each market group in the same file if the total of any market group is greater than zero. Basically print the rows with count greater than zero.

 

I am new to summary reporting so any help is greatly appreciated.

 

Thanks for your time!

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

Hi @Cbob03 

 

Here is an approach to achieve this form the input dataset HAVE:

proc means data=have sum noprint;
	var MKT PHL MRC DRA NUC;
	class dt;
	ways 1;
	output out=want (drop=_:) sum=MKT PHL MRC DRA NUC;
quit;

%macro print_market (market);
	ods excel options(sheet_name="&market");
	proc print data=have;
		title "&market";
		var dt;
		ID ID;
		where &market > 0;
	run;
%mend;

/* Report */

ods excel file='/PATH/results.xlsx' options (sheet_name="Summary") /* <--- update PATH */ ;

	proc print data=want;
		title "Summary";
		id dt;
		sum MKT PHL MRC DRA NUC;
	run;

	%print_market(MKT)
	%print_market(PHL)
	%print_market(MRC)
	%print_market(DRA)
	%print_market(NUC)
;

ods excel close;

Best,

 

 

View solution in original post

3 REPLIES 3
andreas_lds
Jade | Level 19

Please post the data you have as dataset using datalines, also post the expected result in the same form or as screenshot. I won't open any office-documents.

ed_sas_member
Meteorite | Level 14

Hi @Cbob03 

 

Here is an approach to achieve this form the input dataset HAVE:

proc means data=have sum noprint;
	var MKT PHL MRC DRA NUC;
	class dt;
	ways 1;
	output out=want (drop=_:) sum=MKT PHL MRC DRA NUC;
quit;

%macro print_market (market);
	ods excel options(sheet_name="&market");
	proc print data=have;
		title "&market";
		var dt;
		ID ID;
		where &market > 0;
	run;
%mend;

/* Report */

ods excel file='/PATH/results.xlsx' options (sheet_name="Summary") /* <--- update PATH */ ;

	proc print data=want;
		title "Summary";
		id dt;
		sum MKT PHL MRC DRA NUC;
	run;

	%print_market(MKT)
	%print_market(PHL)
	%print_market(MRC)
	%print_market(DRA)
	%print_market(NUC)
;

ods excel close;

Best,

 

 

Cbob03
Fluorite | Level 6
Thank you very much!!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 560 views
  • 0 likes
  • 3 in conversation