<?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 Re: computed variables under across variables in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693206#M24599</link>
    <description>&lt;P&gt;This would be pretty simple if you wanted a column for the MEDIAN, another column for the Q1 and another column for the Q3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you absolutely must have a text string rather than the actual numeric values (why?), then I think you need some help from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 21 Oct 2020 14:49:24 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-10-21T14:49:24Z</dc:date>
    <item>
      <title>computed variables under across variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693191#M24595</link>
      <description>&lt;P&gt;Dear community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to collapse median, q1 and q3 for an analysis variable to have them displayed in one cell in the final report. It works as long as I use only group variables, as soon as I switch to across variables I get an error:&lt;/P&gt;&lt;P&gt;ERROR: The variable type of 'MSRP.MEDIAN'n is invalid in this context.&lt;/P&gt;&lt;P&gt;So this works:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=sashelp.cars;
	columns Origin Make Type msrp msrp=msrpq1 msrp=msrpq3 stats;
	define Origin /" " group;
	define Make /" " group;
	define Type / " " group;

	define msrp / analysis median noprint;
	define msrpq1 / analysis q1 noprint;
	define msrpq3 / analysis q3 noprint;
	define stats / computed;

	compute stats / character length=50;
		stats = catt(put(msrp.median, dollar7.1-l), " (", put(msrpq1, dollar7.1-l), "-", put(msrpq3, dollar7.1-l), ")");
	endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But this does not:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=sashelp.cars;
	columns Origin Make Type msrp msrp=msrpq1 msrp=msrpq3 stats;
	define Origin /" " group;
	define Make /" " group;
	define Type / " " group;

	define msrp / analysis median noprint;
	define msrpq1 / analysis q1 noprint;
	define msrpq3 / analysis q3 noprint;
	define stats / computed;

	compute stats / character length=50;
		stats = catt(put(msrp.median, dollar7.1-l), " (", put(msrpq1, dollar7.1-l), "-", put(msrpq3, dollar7.1-l), ")");
	endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Ultimately I would like to obtain a table similar to one generated by below code, but with median, q1 and q3 collapsed into one computed variable:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=sashelp.cars;
	columns Origin Make Type, msrp, (n median q1 q3);
	define Origin /" " group;
	define Make /" " group;
	define Type / " " across;
	define n / format=2.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What am I missing? Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 14:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693191#M24595</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2020-10-21T14:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: computed variables under across variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693196#M24596</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223838"&gt;@js5&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;But this does not:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=sashelp.cars;
	columns Origin Make Type msrp msrp=msrpq1 msrp=msrpq3 stats;
	define Origin /" " group;
	define Make /" " group;
	define Type / " " group;

	define msrp / analysis median noprint;
	define msrpq1 / analysis q1 noprint;
	define msrpq3 / analysis q3 noprint;
	define stats / computed;

	compute stats / character length=50;
		stats = catt(put(msrp.median, dollar7.1-l), " (", put(msrpq1, dollar7.1-l), "-", put(msrpq3, dollar7.1-l), ")");
	endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Works for me. What errors are you seeing from this code?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 14:29:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693196#M24596</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-21T14:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: computed variables under across variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693198#M24597</link>
      <description>&lt;P&gt;Apologies, I made a copy-paste error. This is the failing code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=sashelp.cars;
	columns Origin Make Type, msrp msrp=msrpq1 msrp=msrpq3 stats;
	define Origin /" " group;
	define Make /" " group;
	define Type / " " across;

	define msrp / analysis median noprint;
	define msrpq1 / analysis q1 noprint;
	define msrpq3 / analysis q3 noprint;
	define stats / computed;

	compute stats / character length=50;
		stats = catt(put(msrp.median, dollar7.1-l), " (", put(msrpq1, dollar7.1-l), "-", put(msrpq3, dollar7.1-l), ")");
	endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I.e. with Type as across variable.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 14:34:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693198#M24597</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2020-10-21T14:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: computed variables under across variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693199#M24598</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223838"&gt;@js5&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to collapse median, q1 and q3 for an analysis variable to have them displayed in one cell in the final report. It works as long as I use only group variables, as soon as I switch to across variables I get an error:&lt;/P&gt;
&lt;P&gt;ERROR: The variable type of 'MSRP.MEDIAN'n is invalid in this context.&lt;/P&gt;
&lt;P&gt;So this works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=sashelp.cars;
	columns Origin Make Type msrp msrp=msrpq1 msrp=msrpq3 stats;
	define Origin /" " group;
	define Make /" " group;
	define Type / " " group;

	define msrp / analysis median noprint;
	define msrpq1 / analysis q1 noprint;
	define msrpq3 / analysis q3 noprint;
	define stats / computed;

	compute stats / character length=50;
		stats = catt(put(msrp.median, dollar7.1-l), " (", put(msrpq1, dollar7.1-l), "-", put(msrpq3, dollar7.1-l), ")");
	endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But this does not:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=sashelp.cars;
	columns Origin Make Type msrp msrp=msrpq1 msrp=msrpq3 stats;
	define Origin /" " group;
	define Make /" " group;
	define Type / " " group;

	define msrp / analysis median noprint;
	define msrpq1 / analysis q1 noprint;
	define msrpq3 / analysis q3 noprint;
	define stats / computed;

	compute stats / character length=50;
		stats = catt(put(msrp.median, dollar7.1-l), " (", put(msrpq1, dollar7.1-l), "-", put(msrpq3, dollar7.1-l), ")");
	endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Ultimately I would like to obtain a table similar to one generated by below code, but with median, q1 and q3 collapsed into one computed variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=sashelp.cars;
	columns Origin Make Type, msrp, (n median q1 q3);
	define Origin /" " group;
	define Make /" " group;
	define Type / " " across;
	define n / format=2.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What am I missing? Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please double check your posted code. Your second block of code does not contain any ACROSS variables.&amp;nbsp; If I change the Type to across I do not get that error, though the output is likely not what you want either. So, as with any error: Copy from the log the entire procedure code and any messages and then paste that to the forum in a code box opened with the &amp;lt;/&amp;gt; icon to preserve formatting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally I would likely pre-calculate the string using proc summary followed by a data step and then just have the group,across variables and that string value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 14:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693199#M24598</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-21T14:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: computed variables under across variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693206#M24599</link>
      <description>&lt;P&gt;This would be pretty simple if you wanted a column for the MEDIAN, another column for the Q1 and another column for the Q3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you absolutely must have a text string rather than the actual numeric values (why?), then I think you need some help from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 14:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693206#M24599</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-21T14:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: computed variables under across variablesiables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693212#M24600</link>
      <description>&lt;P&gt;You need a different variable nested under across.&amp;nbsp; I'm not sure why you're using ACROSS if all the variables under are NOPRINT. &amp;nbsp; This fixed the context issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=sashelp.cars /*list showall*/;
	columns Origin Make Type, (msrp) msrp=msrp0 msrp=msrpq1 msrp=msrpq3 stats;
	define Origin /" " group;
	define Make /" " group;
	define Type / " " across;
   define msrp    / n noprint; *&amp;lt;===;
	define msrp0   / analysis median noprint;
	define msrpq1 / analysis q1 noprint;
	define msrpq3 / analysis q3 noprint;
	define stats  / computed;

	compute stats / character length=50;
		stats = catt(put(msrp0, dollar7.1-l), " (", put(msrpq1, dollar7.1-l), "-", put(msrpq3, dollar7.1-l), ")");
	endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Oct 2020 15:02:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693212#M24600</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2020-10-21T15:02:40Z</dc:date>
    </item>
    <item>
      <title>Re: computed variables under across variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693225#M24601</link>
      <description>&lt;P&gt;You may want to reference this document &lt;A href="https://support.sas.com/resources/papers/proceedings15/SAS1642-2015.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings15/SAS1642-2015.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because of the way ACROSS creates columns you have to reference the specific column number for calculations. Which I believe means that you have to test for which column the type is in and then compute with separate columns. I think.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like I mentioned, likely much easier to make this variable BEFORE Proc Report and then just display it.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 15:29:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693225#M24601</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-21T15:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: computed variables under across variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693278#M24602</link>
      <description>&lt;P&gt;Hi: Thanks for the vote of confidence &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;. This paper &lt;A href="https://support.sas.com/resources/papers/proceedings14/SAS388-2014.pdf" target="_blank" rel="noopener"&gt;https://support.sas.com/resources/papers/proceedings14/SAS388-2014.pdf&lt;/A&gt; goes into detail on using ACROSS items. And using a subset of SASHELP.CARS, if I understand what the original poster wants, I'd use THIS approach shown below:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1603306472945.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50885iF469BCE6978E536F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1603306472945.png" alt="Cynthia_sas_0-1603306472945.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The way to find out what the correct absolute column numbers are is shown in my user group paper.&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 18:55:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693278#M24602</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-10-21T18:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: computed variables under across variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693405#M24603</link>
      <description>&lt;P&gt;Thank you for the responses!&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;'s solution does run, but type is not shown as across variable. The report has 3 columns: Origin, Make and Stats.&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;'s solution does indeed produce the intended result, with the disadvantage of having to refer to values by column numbers instead of variable names. Reading the paper, it appears there is no way around it, correct? In this case I might do what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;said and pre-calculate the concatenated column as the actual data I need to display has considerably more across groups.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 06:55:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693405#M24603</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2020-10-22T06:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: computed variables under across variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693606#M24604</link>
      <description>&lt;P&gt;Hi:&lt;BR /&gt;You MUST refer to the items under an ACROSS item by the absolute column number in a COMPUTE block. There's no way around this except to "pre-calculate" the values you want with PROC MEANS or PROC TABULATE. Even PROC REPORT would pre-summarize for you but for this purpose, I think PROC MEANS is the way to go:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1603395342788.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50914i1C589E4EA23212D2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1603395342788.png" alt="Cynthia_sas_0-1603395342788.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;Cynthia&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 19:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693606#M24604</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-10-22T19:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: computed variables under across variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693662#M24605</link>
      <description>This is exactly what I did, except that instead of using a dummy variable, I defined string as a group variable. According to &lt;A href="https://blogs.sas.com/content/sgf/2014/03/14/how-to-avoid-6-common-proc-report-errors/" target="_blank"&gt;https://blogs.sas.com/content/sgf/2014/03/14/how-to-avoid-6-common-proc-report-errors/&lt;/A&gt; it is a valid solution too.</description>
      <pubDate>Fri, 23 Oct 2020 06:15:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693662#M24605</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2020-10-23T06:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: computed variables under across variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693737#M24606</link>
      <description>Hi:&lt;BR /&gt;  Yes, that is an alternative. The dummy variable way has been handy for me because using a dummy variable at the end of a row is also useful if I need to go back and do any conditional changes based on multiple items in the report row. Since it serves a double purpose, it's the one I generally use. &lt;BR /&gt;Cynthia</description>
      <pubDate>Fri, 23 Oct 2020 14:56:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/computed-variables-under-across-variables/m-p/693737#M24606</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-10-23T14:56:24Z</dc:date>
    </item>
  </channel>
</rss>

