BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Q1983
Lapis Lazuli | Level 10
proc sql;
create table ic1 as
select 
		Ad_1,
		Pl_2
from ic
;quit;

proc sql;
create table cc1 as
select 
		H1_1,
		Pl_2
from pc
;quit;

%macro Report(report,sheet_nm);				
				
ODS TAGSETS.ExcelXP				
   options(sheet_interval='none'				
           absolute_column_width='8'				
           sheet_name=&sheet_nm.);
PROC REPORT DATA=&Report. headskip split='*' wrap nowd ;
columns Ad_1 Pl_2 H1_1 Pl_2;
	run;

%mend Report;				
				
%Report(ic1,"IC");	
%Report(cc1,"CC");

ODS TAGSETS.ExcelXP close;
  ods listing;

You cannot run this code however here is the question.  In the columns area I list all 4 fields. However I want to just show the two fields that belong to the dataset as I have defined them in ic1 and cc1.  The current code would list all 4 in both outputs.  Is there a way to accomplish this without separating the individual proc report references.  Even though I show only 4 fields my actual project has about 20 fields.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@Q1983 wrote:

In the columns area I list all 4 fields. However I want to just show the two fields that belong to the dataset as I have defined them in ic1 and cc1.  The current code would list all 4 in both outputs.  Is there a way to accomplish this without separating the individual proc report references.


I'm not really sure what this means, but here is my guess as to what you mean. If this isn't what you want, explain in more detail.

 

%macro Report(report,sheet_nm,columns);				
				
ODS TAGSETS.ExcelXP				
   options(sheet_interval='none' absolute_column_width='8' sheet_name="&sheet_nm.");
PROC REPORT DATA=&Report. headskip split='*' wrap nowd ;
    columns &columns;
run;
ODS TAGSETS.ExcelXP close;
%mend Report;				
				
%Report(ic1,IC,Ad_1 Pl_2)
%Report(cc1,CC,H1_1 Pl_2)

 

Note your original code has ODS Tagsets.ExcelXP inside the macro, and ODS TAGSETS.EXCELXP CLOSE; outside the macro. This can't be right, but I don't know which way you want it. In any event, both ODS calls should both be inside the macro or both be outside the macro; and if they are outside the macro you need an additional ODS Tagsets inside the macro to set the sheet name.

 

By the way, why ODS TAGSETS Excel.XP when ODS EXCEL is avialable?

--
Paige Miller

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26

@Q1983 wrote:

In the columns area I list all 4 fields. However I want to just show the two fields that belong to the dataset as I have defined them in ic1 and cc1.  The current code would list all 4 in both outputs.  Is there a way to accomplish this without separating the individual proc report references.


I'm not really sure what this means, but here is my guess as to what you mean. If this isn't what you want, explain in more detail.

 

%macro Report(report,sheet_nm,columns);				
				
ODS TAGSETS.ExcelXP				
   options(sheet_interval='none' absolute_column_width='8' sheet_name="&sheet_nm.");
PROC REPORT DATA=&Report. headskip split='*' wrap nowd ;
    columns &columns;
run;
ODS TAGSETS.ExcelXP close;
%mend Report;				
				
%Report(ic1,IC,Ad_1 Pl_2)
%Report(cc1,CC,H1_1 Pl_2)

 

Note your original code has ODS Tagsets.ExcelXP inside the macro, and ODS TAGSETS.EXCELXP CLOSE; outside the macro. This can't be right, but I don't know which way you want it. In any event, both ODS calls should both be inside the macro or both be outside the macro; and if they are outside the macro you need an additional ODS Tagsets inside the macro to set the sheet name.

 

By the way, why ODS TAGSETS Excel.XP when ODS EXCEL is avialable?

--
Paige Miller

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 389 views
  • 1 like
  • 2 in conversation