<?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 Error with computed char variable in PROC REPORT in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Error-with-computed-char-variable-in-PROC-REPORT/m-p/523905#M73473</link>
    <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;In her excellent book (The SAS(R) Programmer's PROC REPORT Handbook:&amp;nbsp;Basic to Advanced Reporting Techniques), Jane&amp;nbsp;Eslinger gave an example of a computed character variable with PROC REPORT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can somebody explain why this computed variable did not work like its equivalent whith a DATA STEP and a PROC PRINT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Source pgm: Eslinger_TW19482_Program2-3.sas ;

title1 "Pgm2-3";
title2 "the computed variable demog is not ok";
proc report data=orders(obs=5);
  column customer_name demog customer_age customer_gender customer_country customer_type;
  define customer_age / display ;
  define customer_gender / display ;
  define customer_country / display ;
  define demog / computed;

  compute demog / char length=20;
    demog = cats(customer_age, "/", customer_gender, "/", customer_country);
  endcomp;
run;

title2 "the computed variable demog is ok";
data ordersmod;
  length demog $ 20;
  set orders(obs=5);
  demog = cats(customer_age, "/", customer_gender, "/", customer_country); 
run;

proc print data=ordersmod;
  var demog;
  var customer_name customer_age customer_gender customer_country;
run;

 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS version 9.4 TS1M3 used with Enterprise Guide 7.13&lt;/P&gt;&lt;P&gt;Source pgm and data can be found at:&amp;nbsp;&lt;A href="https://support.sas.com/downloads/package.htm?pid=1896" target="_blank"&gt;https://support.sas.com/downloads/package.htm?pid=1896&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alain&lt;/P&gt;&lt;P&gt;SAS User&lt;/P&gt;</description>
    <pubDate>Mon, 31 Dec 2018 02:21:05 GMT</pubDate>
    <dc:creator>AVO339</dc:creator>
    <dc:date>2018-12-31T02:21:05Z</dc:date>
    <item>
      <title>Error with computed char variable in PROC REPORT</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-with-computed-char-variable-in-PROC-REPORT/m-p/523905#M73473</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;In her excellent book (The SAS(R) Programmer's PROC REPORT Handbook:&amp;nbsp;Basic to Advanced Reporting Techniques), Jane&amp;nbsp;Eslinger gave an example of a computed character variable with PROC REPORT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can somebody explain why this computed variable did not work like its equivalent whith a DATA STEP and a PROC PRINT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Source pgm: Eslinger_TW19482_Program2-3.sas ;

title1 "Pgm2-3";
title2 "the computed variable demog is not ok";
proc report data=orders(obs=5);
  column customer_name demog customer_age customer_gender customer_country customer_type;
  define customer_age / display ;
  define customer_gender / display ;
  define customer_country / display ;
  define demog / computed;

  compute demog / char length=20;
    demog = cats(customer_age, "/", customer_gender, "/", customer_country);
  endcomp;
run;

title2 "the computed variable demog is ok";
data ordersmod;
  length demog $ 20;
  set orders(obs=5);
  demog = cats(customer_age, "/", customer_gender, "/", customer_country); 
run;

proc print data=ordersmod;
  var demog;
  var customer_name customer_age customer_gender customer_country;
run;

 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS version 9.4 TS1M3 used with Enterprise Guide 7.13&lt;/P&gt;&lt;P&gt;Source pgm and data can be found at:&amp;nbsp;&lt;A href="https://support.sas.com/downloads/package.htm?pid=1896" target="_blank"&gt;https://support.sas.com/downloads/package.htm?pid=1896&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alain&lt;/P&gt;&lt;P&gt;SAS User&lt;/P&gt;</description>
      <pubDate>Mon, 31 Dec 2018 02:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-with-computed-char-variable-in-PROC-REPORT/m-p/523905#M73473</guid>
      <dc:creator>AVO339</dc:creator>
      <dc:date>2018-12-31T02:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: Error with computed char variable in PROC REPORT</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-with-computed-char-variable-in-PROC-REPORT/m-p/523907#M73474</link>
      <description>&lt;P&gt;I'm mot familiar with SAS(R) language. Posting the error message could give a hint to the reason.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may try use the call format instead the function one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;compute demog / char length=20;
    call cats(demog, customer_age, "/", customer_gender, "/", customer_country);
endcomp;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Dec 2018 04:13:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-with-computed-char-variable-in-PROC-REPORT/m-p/523907#M73474</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-12-31T04:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: Error with computed char variable in PROC REPORT</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-with-computed-char-variable-in-PROC-REPORT/m-p/523919#M73475</link>
      <description>&lt;P&gt;The problem is that the variables used in calculating DEMOG are defined after DEMOG itself. Therefore, they are missing at the time you try to compute DEMOG.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To get the computed variable right, you can either change the order of the variables, or you can define the variables used for computing twice (first time with an alias and the NOPRINT option), e.g.:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=orders(obs=5);
  column customer_name  customer_age=x1 customer_gender=x2 customer_country=x3
       demog customer_age customer_gender customer_country;
  define demog / computed;
  define x1 / display noprint;
  define x2 / display noprint;
  define x3 / display noprint;
  define customer_age / display ;
  define customer_gender / display ;
  define customer_country / display;
  compute demog / char length=20;
    demog = cats(x1, "/", x2, "/", x3);
  endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Dec 2018 10:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-with-computed-char-variable-in-PROC-REPORT/m-p/523919#M73475</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-12-31T10:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: Error with computed char variable in PROC REPORT</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-with-computed-char-variable-in-PROC-REPORT/m-p/523928#M73476</link>
      <description>&lt;P&gt;Hi:&lt;BR /&gt; Exactly right answer. This is known as the "left-to-right" rule of PROC REPORT. The DATA step has a Program Data Vector, so the values of all the variables on each row are available to you while the DATA step is processing that row.&lt;BR /&gt;&lt;BR /&gt;However, PROC REPORT only can see the variables in the COLUMN statement and there is NOT any Program Data Vector or buffer area in PROC REPORT that holds all the variables for a row. PROC REPORT places values from the data on the report row one value at a time, working from left to right. So let's say you have 5 variables on the report row, listed in the COLUMN statement:&lt;BR /&gt;column v1 v2 v3 v4 v5;&lt;BR /&gt;&lt;BR /&gt; At the point in time when PROC REPORT is placing V2 on the report row, it has visibility of the values for V1 and V2, but does NOT know what the values for V3, V4 or V5 are. So you could not use any of these values in a COMPUTE block for V1 or V2 because they have not yet been placed on the report row.&lt;BR /&gt;&lt;BR /&gt;That is why PROC REPORT does not work the same as the DATA step.&lt;BR /&gt;&lt;BR /&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Mon, 31 Dec 2018 20:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-with-computed-char-variable-in-PROC-REPORT/m-p/523928#M73476</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-12-31T20:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: Error with computed char variable in PROC REPORT</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-with-computed-char-variable-in-PROC-REPORT/m-p/523932#M73477</link>
      <description>&lt;P&gt;Hi Cynthia.&lt;/P&gt;&lt;P&gt;Thanks for the explanation about the differences between the Data Step PDV and the COLUMN "processing" in PROC REPORT.&lt;/P&gt;&lt;P&gt;Thanks to s_lassen too that brings 2 solutions to this problem.&lt;/P&gt;&lt;P&gt;Thanks to others by proposing ideas even if they were not solutions to this problem&lt;/P&gt;&lt;P&gt;Great Holidays to everybody!&lt;/P&gt;&lt;P&gt;AVO339 (Alain V. French Canadian SAS User)&lt;/P&gt;</description>
      <pubDate>Mon, 31 Dec 2018 14:56:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-with-computed-char-variable-in-PROC-REPORT/m-p/523932#M73477</guid>
      <dc:creator>AVO339</dc:creator>
      <dc:date>2018-12-31T14:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: Error with computed char variable in PROC REPORT</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-with-computed-char-variable-in-PROC-REPORT/m-p/525054#M73511</link>
      <description>&lt;P&gt;And finally the exact SAS documentation reference is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Base SAS® 9.4 Procedures Guide, Seventh Edition&lt;BR /&gt;page 1889&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: The position of a computed variable is important. PROC REPORT assigns&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; values to the columns in a row of a report from left to right. Consequently, you&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cannot base the calculation of a computed variable on any variable that appears&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; to its right in the report.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bottom line: a lesson for me: reading the documentation is what to do first...&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jan 2019 15:05:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-with-computed-char-variable-in-PROC-REPORT/m-p/525054#M73511</guid>
      <dc:creator>AVO339</dc:creator>
      <dc:date>2019-01-07T15:05:28Z</dc:date>
    </item>
  </channel>
</rss>

