使用PROC REPORT导出Excel:如何移除指定分组行?
Got it, let's tackle this problem for you! Since you're using PROC REPORT to build an Excel export and need to remove rows where nom_var is either 'Identification' or 'Revenues', here are a couple of straightforward ways to make that happen:
Method 1: Filter directly in PROC REPORT (simplest approach)
You can exclude the unwanted rows right within your PROC REPORT step by adding a WHERE statement. This filters out the rows before the report is generated, so your grouping and break line logic will automatically ignore those values too.
Here’s how to update your code:
PROC REPORT DATA=your_source_dataset OUT=your_excel_export; /* Add this WHERE clause to exclude the target rows */ WHERE nom_var NOT IN ('Identification', 'Revenues'); COLUMN nom_var your_other_columns_here; /* Keep your existing columns */ DEFINE nom_var / GROUP; /* Your existing group definition */ /* Keep your existing break line logic here */ /* Example: BREAK AFTER nom_var / SKIP; or your custom break formatting */ /* Rest of your DEFINE statements and formatting rules */ RUN;
Just replace your_source_dataset and your_other_columns_here with your actual dataset name and remaining report columns.
Method 2: Pre-filter the dataset (good for reuse)
If you need to use the filtered data for other tasks beyond this report, create a temporary filtered dataset first with a DATA step, then pass that to PROC REPORT:
/* Create a filtered dataset without the unwanted rows */ DATA filtered_dataset; SET your_source_dataset; /* Only keep rows where nom_var isn't the target values */ IF nom_var NOT IN ('Identification', 'Revenues'); RUN; /* Use the filtered dataset in your PROC REPORT */ PROC REPORT DATA=filtered_dataset OUT=your_excel_export; COLUMN nom_var your_other_columns_here; DEFINE nom_var / GROUP; /* Your existing break line logic */ /* Rest of your formatting */ RUN;
Either approach will remove the rows where nom_var is 'Identification' or 'Revenues', and since those values are no longer in the dataset, any break lines associated with them will disappear automatically too.
内容的提问来源于stack exchange,提问作者D. O.

