<?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 length of new variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/length-of-new-variables/m-p/701938#M25844</link>
    <description>&lt;P&gt;in the following codes&lt;/P&gt;&lt;P&gt;libname sasdata "sas_library";&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;set data.chemist (keep =job-code);&lt;/P&gt;&lt;P&gt;if job_code='chem3'&lt;/P&gt;&lt;P&gt;then description = 'senior chmistor';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if job_code is a character with a length of 6 bytes, what is the length of variable description?&amp;nbsp; &amp;nbsp;The answer is 14 bytes. I do not know how to get it.&lt;/P&gt;</description>
    <pubDate>Fri, 27 Nov 2020 01:16:18 GMT</pubDate>
    <dc:creator>anming</dc:creator>
    <dc:date>2020-11-27T01:16:18Z</dc:date>
    <item>
      <title>length of new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/length-of-new-variables/m-p/701938#M25844</link>
      <description>&lt;P&gt;in the following codes&lt;/P&gt;&lt;P&gt;libname sasdata "sas_library";&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;set data.chemist (keep =job-code);&lt;/P&gt;&lt;P&gt;if job_code='chem3'&lt;/P&gt;&lt;P&gt;then description = 'senior chmistor';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if job_code is a character with a length of 6 bytes, what is the length of variable description?&amp;nbsp; &amp;nbsp;The answer is 14 bytes. I do not know how to get it.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2020 01:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/length-of-new-variables/m-p/701938#M25844</guid>
      <dc:creator>anming</dc:creator>
      <dc:date>2020-11-27T01:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: length of new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/length-of-new-variables/m-p/701947#M25845</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/356091"&gt;@anming&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;in the following codes&lt;/P&gt;
&lt;P&gt;libname sasdata "sas_library";&lt;/P&gt;
&lt;P&gt;data test;&lt;/P&gt;
&lt;P&gt;set data.chemist (keep =job-code);&lt;/P&gt;
&lt;P&gt;if job_code='chem3'&lt;/P&gt;
&lt;P&gt;then description = 'senior chmistor';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if job_code is a character with a length of 6 bytes, what is the length of variable description?&amp;nbsp; &amp;nbsp;The answer is 14 bytes. I do not know how to get it.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First, do you really have a length of 14 and not 15?&amp;nbsp; 15 is what I get when I imitate your code, assuming description is a new variables.&lt;/P&gt;
&lt;P&gt;Second, is description already in data.chemist?&amp;nbsp; If so, then the above DATA TEST step will not modify it.&lt;/P&gt;
&lt;P&gt;Third, have you shown us all the code in this step/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And finaly, why do you expect the length of job_code to have an impact on the length of decription?&amp;nbsp; After all, job_code is not part of the value assigned to description.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To take it a little further, what if you had something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if job_tenure&amp;gt;10 then 
  then description = 'senior chmistor';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is a case where job_tenure is not even a character variable - so there would be no way to imagine it having a length that would impact the length of description.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2020 02:26:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/length-of-new-variables/m-p/701947#M25845</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-11-27T02:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: length of new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/length-of-new-variables/m-p/701951#M25846</link>
      <description>Sorry, there is a typo in my original codes. It should be "senior chemist". This is a question I copied from one exercise for SAS base certificate. I can not understand how the length of the variable "description" is defined. I can also simulate this piece of codes.</description>
      <pubDate>Fri, 27 Nov 2020 03:13:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/length-of-new-variables/m-p/701951#M25846</guid>
      <dc:creator>anming</dc:creator>
      <dc:date>2020-11-27T03:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: length of new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/length-of-new-variables/m-p/701954#M25847</link>
      <description>I checked it. Guess some messages should be given. There is no info about data.chemist, it is probably hard to figure out a proper answer.</description>
      <pubDate>Fri, 27 Nov 2020 03:23:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/length-of-new-variables/m-p/701954#M25847</guid>
      <dc:creator>anming</dc:creator>
      <dc:date>2020-11-27T03:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: length of new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/length-of-new-variables/m-p/701961#M25849</link>
      <description>&lt;P&gt;First, I should not have bothered asking you about the possibility of description being an incoming variable, since you had a "keep=job_code" parameter.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to your question, SAS sees no length statement for the new variable description, but it does see that the value you assign to it contains 14 characters, so it stores the variable with a length of 14.&amp;nbsp; It would not matter if a subsequent assignment required a differing number of letters, because the compiler's first encounter with variable description fixes the length.&amp;nbsp; Shorter values will have trailing blanks, and longer values will be truncated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider the two steps below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  set data.chemist (keep =job_code);
  if job_code='chem3' then description = 'Senior Chemist';
  else if job_code='???' then description='Other';
run;

data test2;
  set data.chemist (keep =job_code);
  if job_code='???' then description = 'Other';
  else if job_code='chem3' then description='senior chemist';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In DATA TEST, there is another possible value assignment ('Other' requiring 5 bytes).&amp;nbsp; TEST will have description with 14 characters.&amp;nbsp; But TEST2, which is logically equivalent to TEST will store description with a length of 5, because the first instance of a value assignment only takes 5 letters.&amp;nbsp; It won't matter that a later assignment needs 14 - only the first 5 will be stored in the data set.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2020 05:40:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/length-of-new-variables/m-p/701961#M25849</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-11-27T05:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: length of new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/length-of-new-variables/m-p/701964#M25850</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/356091"&gt;@anming&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I checked it. Guess some messages should be given. There is no info about data.chemist, it is probably hard to figure out a proper answer.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In fact, it is not hard at all, because the data-step in the task contains all information necessary to answer the question.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname sasdata "sas_library";

data test;
  set data.chemist(keep= job_code);

  if job_code = 'chem3' then description = 'senior chmistor';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The SET-statement with keep tells, that only one variable is read form data.chemist. =&amp;gt; No type/length information for "description".&lt;/LI&gt;
&lt;LI&gt;The data-step has neither length nor attrib statement defining "description" =&amp;gt; length and type are defined by the first assignment =&amp;gt; count the number of chars to answer the question.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2020 06:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/length-of-new-variables/m-p/701964#M25850</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-11-27T06:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: length of new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/length-of-new-variables/m-p/702033#M25852</link>
      <description>Great! my confusion is that bytes. does 14 characters of 'senior chemist' including one space mean 14 bytes? Thanks!</description>
      <pubDate>Fri, 27 Nov 2020 14:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/length-of-new-variables/m-p/702033#M25852</guid>
      <dc:creator>anming</dc:creator>
      <dc:date>2020-11-27T14:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: length of new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/length-of-new-variables/m-p/702034#M25853</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/356091"&gt;@anming&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Great! my confusion is that bytes. does 14 characters of 'senior chemist' including one space mean 14 bytes? Thanks!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In most cases. All of the characters in that string are standard 7-bit ASCII characters so each one needs just one byte whatever encoding you are using.&amp;nbsp; The exception is if your SAS session is using double byte encoding (an pre UTF-8 method mainly used for Asian languages) in which case the length would be 28 bytes.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2020 14:50:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/length-of-new-variables/m-p/702034#M25853</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-27T14:50:51Z</dc:date>
    </item>
  </channel>
</rss>

