<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Compute a sum and label it in proc report in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compute-a-sum-and-label-it-in-proc-report/m-p/925380#M364178</link>
    <description>&lt;P&gt;Hello there,&lt;/P&gt;
&lt;P&gt;I am trying to compute an additional row that contains a label and the sum of certain columns. My Output looks like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jakobsen96_0-1713879857994.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95776iD82D4885C50FB7CB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jakobsen96_0-1713879857994.png" alt="Jakobsen96_0-1713879857994.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;As you can see the labeling and computing works fine for the second table (Variable ATBG10A), but not for my other tables (ACXG48...). I guess the problem is that the "ACXG48..." variables are numeric. The Log shows the following hints:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="sasLogNote17_1713879120711" class="sasNote"&gt;NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column). 1:12&lt;/DIV&gt;
&lt;DIV id="sasLogNote18_1713879120711" class="sasNote"&gt;NOTE: Format ACXG48A was not found or could not be loaded.&lt;/DIV&gt;
&lt;DIV id="sasLogNote19_1713879120711" class="sasNote focus-line"&gt;NOTE: Invalid numeric data, 'Gesamt' , at Zeile 1 Spalte 12.&lt;/DIV&gt;
&lt;DIV class="sasNote focus-line"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote focus-line"&gt;Do you have any guidance on how to change the format of the ACXG48... variables? Or is my approch the wrong one anyway? My code looks like this and I have also attached the data and the code:&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*** Libname path ***/
%let dpath = yourpath; /* Change path */
Libname d "&amp;amp;dpath";


/* Macro Variable for Sorting */
proc sql noprint;
  select distinct Sort into :Sort separated by " "
  from d.Excelbeispiel2;
quit;

/*** Macro for PDF ***/
ods _all_ close;
ods escapechar="^";
%macro SkaTest (nvariables=);
  %do i = 1 %to &amp;amp;nvariables;
    %let SortID = %scan(&amp;amp;Sort., &amp;amp;i.);
	ods html close;

/* Use Info1 Column to iterate over Itemnames */
   %local Info1Items; 
   proc sql noprint; 
      select distinct Info1 into :Info1Items separated by " "
      from d.ExcelBeispiel2
      where Sort = &amp;amp;SortID.;
   quit; 
   
/* Data for Iteration Cycles */
   data d.QuellenBeispiel;
    	set d.ExcelBeispiel2;
    	where Sort = &amp;amp;SortID.;
    	drop Part;
   run;

ods pdf startpage=never;
ods layout gridded x=1cm columns=1;

/* Print variable Information */ 	
    ods region;
    proc report data=d.QuellenBeispiel noheader;
    	column Info1 Info2 Bsort;
    	define Info1 / display;
    	define Info2 / display;
    	define Bsort / noprint;
    	compute Info1;
    		Info1 = tranwrd(Info1,"Kodierung","^{style[fontweight=bold]Kodierung}");
    	endcomp;
    	compute Bsort;
    		if Bsort = "*" then do;
    		call define (_ROW_,"style","style={font_weight=bold fontsize=10pt}");
    		end;
    		if Bsort ="~" then do;
    		call define (_row_, "style", "style={backgroundcolor=lightgrey fontweight=bold}");
    		end;
    	endcomp;
    run;
    
ods layout end;

/* Macro to match variable information with frequency tables */
ods layout gridded x=1cm columns=2;
%macro PrintItem(Item=);

	%if %sysfunc(exist(d.F&amp;amp;Item.)) %then %do;
	ods region;
      proc report data=d.F&amp;amp;Item.;
        column &amp;amp;Item. n pct pct_se;
        define &amp;amp;Item. / display "&amp;amp;Item" style(header)=[backgroundcolor=lightgrey];
        define n / "Absolut" style(header)=[backgroundcolor=lightgrey];
        define pct / "Prozent" width=12 format=6.2 style(header)=[backgroundcolor=lightgrey];
        define pct_se / display "(SE)" format=6.2 style(header)=[backgroundcolor=lightgrey];
        rbreak after / summarize
        	style(summary) = {font_weight=bold};
        compute after ;
        	&amp;amp;Item. = "Gesamt";
        endcomp;
      run;
    %end;
    
    %if %sysfunc(exist(d.M&amp;amp;Item.)) %then %do;
	ods region;
      proc report data=d.M&amp;amp;Item.;
        column dvar mnx mnx_se sdx Min Max n; 
        define dvar / display "Variable" style(header)=[backgroundcolor=lightgrey];
        define mnx / "M" format=6.2 style(header)=[backgroundcolor=lightgrey];
        define mnx_se / display "(SE)" format=6.2 style(header)=[backgroundcolor=lightgrey];
        define sdx / display "SD" format=6.2 style(header)=[backgroundcolor=lightgrey];
        define Min / display "Min" format=6.0 style(column) = {just = center} style(header)=[backgroundcolor=lightgrey];
        define Max / display "Max" format=6.0 style(column) = {just = center} style(header)=[backgroundcolor=lightgrey];
        define n / display "n" style(header)=[backgroundcolor=lightgrey];
        rbreak after / summarize
        	style(summary) = {font_weight=bold};
        compute after ;
        	dvar = "Gesamt";
        endcomp;
      run;
	%end; 

%mend PrintItem;
 
   %local j currItem; 
   %let j=1; 
   %let currItem=%scan(&amp;amp;Info1Items.,&amp;amp;j.,%str( )); 
   
   %do %while(%length(&amp;amp;currItem.)&amp;gt;0); 
  
      %PrintItem(Item=&amp;amp;currItem.); 
      %let j=%eval(&amp;amp;j.+1); 
      %let currItem=%scan(&amp;amp;Info1Items.,&amp;amp;j.,%str( )); 
      
   %end; 
   
ods layout end;   
  %end;
  
%mend SkaTest;

/* Print PDF */
options papersize=a4 orientation=portrait leftmargin=0.5cm rightmargin=0.5cm topmargin=0.5cm bottommargin=0.5cm nodate nonumber pdfprint=HRES;
ods listing close;
ods pdf file="yourpath\TestPDF2.pdf";
%SkaTest(nvariables = 2);
ods pdf close;
&lt;/CODE&gt;&lt;/PRE&gt;
Thank you!&lt;/DIV&gt;
&lt;DIV class="sasNote focus-line"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote focus-line"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Apr 2024 13:52:58 GMT</pubDate>
    <dc:creator>_Manhattan</dc:creator>
    <dc:date>2024-04-23T13:52:58Z</dc:date>
    <item>
      <title>Compute a sum and label it in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-a-sum-and-label-it-in-proc-report/m-p/925380#M364178</link>
      <description>&lt;P&gt;Hello there,&lt;/P&gt;
&lt;P&gt;I am trying to compute an additional row that contains a label and the sum of certain columns. My Output looks like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jakobsen96_0-1713879857994.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95776iD82D4885C50FB7CB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jakobsen96_0-1713879857994.png" alt="Jakobsen96_0-1713879857994.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;As you can see the labeling and computing works fine for the second table (Variable ATBG10A), but not for my other tables (ACXG48...). I guess the problem is that the "ACXG48..." variables are numeric. The Log shows the following hints:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="sasLogNote17_1713879120711" class="sasNote"&gt;NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column). 1:12&lt;/DIV&gt;
&lt;DIV id="sasLogNote18_1713879120711" class="sasNote"&gt;NOTE: Format ACXG48A was not found or could not be loaded.&lt;/DIV&gt;
&lt;DIV id="sasLogNote19_1713879120711" class="sasNote focus-line"&gt;NOTE: Invalid numeric data, 'Gesamt' , at Zeile 1 Spalte 12.&lt;/DIV&gt;
&lt;DIV class="sasNote focus-line"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote focus-line"&gt;Do you have any guidance on how to change the format of the ACXG48... variables? Or is my approch the wrong one anyway? My code looks like this and I have also attached the data and the code:&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*** Libname path ***/
%let dpath = yourpath; /* Change path */
Libname d "&amp;amp;dpath";


/* Macro Variable for Sorting */
proc sql noprint;
  select distinct Sort into :Sort separated by " "
  from d.Excelbeispiel2;
quit;

/*** Macro for PDF ***/
ods _all_ close;
ods escapechar="^";
%macro SkaTest (nvariables=);
  %do i = 1 %to &amp;amp;nvariables;
    %let SortID = %scan(&amp;amp;Sort., &amp;amp;i.);
	ods html close;

/* Use Info1 Column to iterate over Itemnames */
   %local Info1Items; 
   proc sql noprint; 
      select distinct Info1 into :Info1Items separated by " "
      from d.ExcelBeispiel2
      where Sort = &amp;amp;SortID.;
   quit; 
   
/* Data for Iteration Cycles */
   data d.QuellenBeispiel;
    	set d.ExcelBeispiel2;
    	where Sort = &amp;amp;SortID.;
    	drop Part;
   run;

ods pdf startpage=never;
ods layout gridded x=1cm columns=1;

/* Print variable Information */ 	
    ods region;
    proc report data=d.QuellenBeispiel noheader;
    	column Info1 Info2 Bsort;
    	define Info1 / display;
    	define Info2 / display;
    	define Bsort / noprint;
    	compute Info1;
    		Info1 = tranwrd(Info1,"Kodierung","^{style[fontweight=bold]Kodierung}");
    	endcomp;
    	compute Bsort;
    		if Bsort = "*" then do;
    		call define (_ROW_,"style","style={font_weight=bold fontsize=10pt}");
    		end;
    		if Bsort ="~" then do;
    		call define (_row_, "style", "style={backgroundcolor=lightgrey fontweight=bold}");
    		end;
    	endcomp;
    run;
    
ods layout end;

/* Macro to match variable information with frequency tables */
ods layout gridded x=1cm columns=2;
%macro PrintItem(Item=);

	%if %sysfunc(exist(d.F&amp;amp;Item.)) %then %do;
	ods region;
      proc report data=d.F&amp;amp;Item.;
        column &amp;amp;Item. n pct pct_se;
        define &amp;amp;Item. / display "&amp;amp;Item" style(header)=[backgroundcolor=lightgrey];
        define n / "Absolut" style(header)=[backgroundcolor=lightgrey];
        define pct / "Prozent" width=12 format=6.2 style(header)=[backgroundcolor=lightgrey];
        define pct_se / display "(SE)" format=6.2 style(header)=[backgroundcolor=lightgrey];
        rbreak after / summarize
        	style(summary) = {font_weight=bold};
        compute after ;
        	&amp;amp;Item. = "Gesamt";
        endcomp;
      run;
    %end;
    
    %if %sysfunc(exist(d.M&amp;amp;Item.)) %then %do;
	ods region;
      proc report data=d.M&amp;amp;Item.;
        column dvar mnx mnx_se sdx Min Max n; 
        define dvar / display "Variable" style(header)=[backgroundcolor=lightgrey];
        define mnx / "M" format=6.2 style(header)=[backgroundcolor=lightgrey];
        define mnx_se / display "(SE)" format=6.2 style(header)=[backgroundcolor=lightgrey];
        define sdx / display "SD" format=6.2 style(header)=[backgroundcolor=lightgrey];
        define Min / display "Min" format=6.0 style(column) = {just = center} style(header)=[backgroundcolor=lightgrey];
        define Max / display "Max" format=6.0 style(column) = {just = center} style(header)=[backgroundcolor=lightgrey];
        define n / display "n" style(header)=[backgroundcolor=lightgrey];
        rbreak after / summarize
        	style(summary) = {font_weight=bold};
        compute after ;
        	dvar = "Gesamt";
        endcomp;
      run;
	%end; 

%mend PrintItem;
 
   %local j currItem; 
   %let j=1; 
   %let currItem=%scan(&amp;amp;Info1Items.,&amp;amp;j.,%str( )); 
   
   %do %while(%length(&amp;amp;currItem.)&amp;gt;0); 
  
      %PrintItem(Item=&amp;amp;currItem.); 
      %let j=%eval(&amp;amp;j.+1); 
      %let currItem=%scan(&amp;amp;Info1Items.,&amp;amp;j.,%str( )); 
      
   %end; 
   
ods layout end;   
  %end;
  
%mend SkaTest;

/* Print PDF */
options papersize=a4 orientation=portrait leftmargin=0.5cm rightmargin=0.5cm topmargin=0.5cm bottommargin=0.5cm nodate nonumber pdfprint=HRES;
ods listing close;
ods pdf file="yourpath\TestPDF2.pdf";
%SkaTest(nvariables = 2);
ods pdf close;
&lt;/CODE&gt;&lt;/PRE&gt;
Thank you!&lt;/DIV&gt;
&lt;DIV class="sasNote focus-line"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote focus-line"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2024 13:52:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-a-sum-and-label-it-in-proc-report/m-p/925380#M364178</guid>
      <dc:creator>_Manhattan</dc:creator>
      <dc:date>2024-04-23T13:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: Compute a sum and label it in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-a-sum-and-label-it-in-proc-report/m-p/925413#M364187</link>
      <description>&lt;P&gt;So that variable is NUMERIC.&amp;nbsp; You cannot store "TOTAL"&amp;nbsp; (or "Gesamt") into a numeric variable, you need a character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It also has a format attached to it that you did not provide.&amp;nbsp; We can test anyway by setting NOFMTERR system option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A simple way to fix that is to convert it to a character variable.&amp;nbsp; You might be able to do it in PROC REPORT, but it is probably easier to do it in a data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let item=ACXG48A;
options nofmterr ;
libname d 'c:\downloads'; 
data for_report;
  set d.f&amp;amp;item(rename=(&amp;amp;item=_&amp;amp;item));
  length &amp;amp;item $30;
  &amp;amp;item=vvalue(_&amp;amp;item);
run;

proc report data=for_report;
  column &amp;amp;Item. n pct pct_se;
  define &amp;amp;Item. / display "&amp;amp;Item" style(header)=[backgroundcolor=lightgrey];
  define n / "Absolut" style(header)=[backgroundcolor=lightgrey];
  define pct / "Prozent" width=12 format=6.2 style(header)=[backgroundcolor=lightgrey];
  define pct_se / display "(SE)" format=6.2 style(header)=[backgroundcolor=lightgrey];
  rbreak after / summarize
    style(summary) = {font_weight=bold};
  compute after ;
    &amp;amp;Item. = "Gesamt";
  endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1713887210792.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95784i14F247C15F7E4A2D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1713887210792.png" alt="Tom_0-1713887210792.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2024 16:10:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-a-sum-and-label-it-in-proc-report/m-p/925413#M364187</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-23T16:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: Compute a sum and label it in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-a-sum-and-label-it-in-proc-report/m-p/925415#M364188</link>
      <description>&lt;P&gt;A drawback turning a numeric variable to a character variable for purposes of reporting, is that character variables are sorted alphabetically, not numerically. So if you had three numeric values, such as 3, 6, 10, then converting these to characters and having them sort alphabetically means you get 10, 3, 6 in order, and this is not what most people want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would leave the variable as numeric, and have a format to place text into the report. Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
    value cylf .='All';
run;
proc report data=sashelp.cars;
    columns cylinders cyl1 msrp;
    define cylinders/group noprint;
    define cyl1/computed format=cylf. 'Cylinders';
    define msrp/mean;
    compute cyl1;
        cyl1=cylinders;
    endcomp;
    rbreak after/summarize style=[font_style=italic];
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Apr 2024 16:38:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-a-sum-and-label-it-in-proc-report/m-p/925415#M364188</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-04-23T16:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: Compute a sum and label it in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-a-sum-and-label-it-in-proc-report/m-p/925426#M364191</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Here's a solution example with PROC REPORT:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1713895578790.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95786i89A8AB6A611B437E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1713895578790.png" alt="Cynthia_sas_0-1713895578790.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; In this example, the character version of the main numeric variable is created in PROC REPORT as a COMPUTED item and so the numeric variable is still used for ordering, but the character version allows you to put your custom text on the break line.&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2024 18:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-a-sum-and-label-it-in-proc-report/m-p/925426#M364191</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2024-04-23T18:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: Compute a sum and label it in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-a-sum-and-label-it-in-proc-report/m-p/925511#M364215</link>
      <description>&lt;P&gt;Thank you so much Cynthia! I have integrated that approach easily in my code &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 08:42:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-a-sum-and-label-it-in-proc-report/m-p/925511#M364215</guid>
      <dc:creator>_Manhattan</dc:creator>
      <dc:date>2024-04-24T08:42:45Z</dc:date>
    </item>
  </channel>
</rss>

