data cars(keep=make model origin weight); set sashelp.cars; run; data cars1(keep=make model); set cars; run; data cars2(keep=make model origin); set cars; run; data cars3(keep=make model origin weight); set cars; run; %let colstyle70 = style(column)={just=left cellwidth=70pt}; %let colstyle90 = style(column)={just=left cellwidth=90pt}; %macro Final(final,sheet_nm); ODS TAGSETS.ExcelXP options(sheet_interval='none' absolute_column_width='8' sheet_name=&sheet_nm. center_horizontal="no" Orientation='Landscape' embedded_titles='No' fittopage="No" blackandwhite="No" auto_filter = "Yes" Embedded_Footnotes='Yes' autofit_height="Yes"); %NoAccountLogic(&final.,&ReportName); PROC REPORT DATA=&final. headskip split='*' wrap nowd ; columns make model origin weight ; Define make / &colstyle90 "Make"; Define model / &colstyle90 "Model"; Define origin / &colstyle90 "Origin"; Define weight / &colstyle90 "Weight"; run; %mend final; %Final(cars1,"Cars1"); %Final(cars2,"Cars2"); %Final(cars3,"Cars3");
I have 3 datasets with the same fields. I want the output to be conditional based on the dataset contents. Note the changes in fields per cars1,2 and 3. Is there a way to do this in ods without repeating each ods output and fields separately?
Since you are doing this in a macro where you pass a parameter with a macro variable holding the name of the set use a single macro variable holding values you are assigning to colstyle70 and colstyle90 conditionally based on the value of the parameter.
Something like the following: (Caution: that = is going to be case sensitive.
%if &final=cars1 %then %let colstyle= style(column)={just=left cellwidth=70pt};
%else %if &final=cars2 %then %let colstyle= style(column)={just=left cellwidth=90pt};
And use a proc report like
Proc report data=&final. headskip split='*' wrap nowd &colstyle ; run;
If you do not provide a COLUMNS statement all the variables will be output by default and the style applied to all columns.
If you need to set per column different style attributes that differ for the same variable in multiple sets then perhaps the macro language isn't worth it. You can spend a lot of time getting one combination to work and then have to start all over for the next. At which point you could have written a custom Proc Report for each faster.
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!
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.
Ready to level-up your skills? Choose your own adventure.