<?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: My string variable is getting cut off despite having set adaquate length, format and informat. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/My-string-variable-is-getting-cut-off-despite-having-set/m-p/705221#M216283</link>
    <description>&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 18.06px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;Thank you. I did not realize that use of a length statement allow you to redefine length in the case where the longest value is shorter. Sounds like I was trying to put a square in round hole. I think that I have resolved this, though I did so in a way that leaves me with questions. The data set that I was using was from gapminder.org. When I downloaded the xlsx file and ran the program, I received an "exception error". I have seem this before and knew it was an unknown formatting bug that would not let me be successful with that version. Next, I downloaded the csv file. This was the file I was having difficulty with when I posted my question. Once you shared the detail about the limitations of the length statement, I again wondered if it was a formatting issue with the original csv file. I opened it and saved the csv as xlsx (rather than downloading the xlsx from the website). This time my length statement before SET achieved what I wanted it to and there was no more truncation. Experience like this have been accumulating for me. That is, I start with a standard file format, but find it does not behave in a standard way. Thanks again for the length tip! Very helpful.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 11 Dec 2020 00:28:18 GMT</pubDate>
    <dc:creator>ldierker1</dc:creator>
    <dc:date>2020-12-11T00:28:18Z</dc:date>
    <item>
      <title>My string variable is getting cut off despite having set adaquate length, format and informat.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-string-variable-is-getting-cut-off-despite-having-set/m-p/705210#M216273</link>
      <description>&lt;DIV&gt;&lt;FONT&gt;&lt;STRONG&gt;My code: &amp;nbsp;&lt;/STRONG&gt; &amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;data new; length country $50 ; format country $50.; informat country $50.; set &amp;nbsp; &amp;nbsp; &amp;nbsp; work.lifeexpectancy;&lt;BR /&gt;keep country _2009 _2010 _2011 _2012 _2013 _2014 _2015 _2016 _2017 _2018;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;proc sort; by country; &lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;proc contents; run; &lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;proc freq; tables country; run; &lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;My output:&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;The contents shows that&lt;STRONG&gt; country&lt;/STRONG&gt; is a character variable with $50 len, $50 format and $50 informat;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;In the table, several strings are getting cut off well before 50 length.&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;e.g. "Sao Tome and Princi" or "St. Vincent and the"&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;This is causing troubles later when I use the string to make secondary variables.&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thank you for your help.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 10 Dec 2020 22:11:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-string-variable-is-getting-cut-off-despite-having-set/m-p/705210#M216273</guid>
      <dc:creator>ldierker1</dc:creator>
      <dc:date>2020-12-10T22:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: My string variable is getting cut off despite having set adaquate length, format and informat.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-string-variable-is-getting-cut-off-despite-having-set/m-p/705212#M216275</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/360430"&gt;@ldierker1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;DIV&gt;&lt;FONT&gt;&lt;STRONG&gt;My code: &amp;nbsp;&lt;/STRONG&gt; &amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT&gt;data new; length country $50 ; format country $50.; informat country $50.; set &amp;nbsp; &amp;nbsp; &amp;nbsp; work.lifeexpectancy;&lt;BR /&gt;keep country _2009 _2010 _2011 _2012 _2013 _2014 _2015 _2016 _2017 _2018;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT&gt;proc sort; by country; &lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT&gt;proc contents; run; &lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT&gt;proc freq; tables country; run; &lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT&gt;My output:&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT&gt;The contents shows that&lt;STRONG&gt; country&lt;/STRONG&gt; is a character variable with $50 len, $50 format and $50 informat;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT&gt;In the table, several strings are getting cut off well before 50 length.&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT&gt;e.g. "Sao Tome and Princi" or "St. Vincent and the"&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT&gt;This is causing troubles later when I use the string to make secondary variables.&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So when you run Proc Contents on&lt;FONT size="5"&gt; &lt;STRONG&gt;work.lifeexpectancy &lt;/STRONG&gt;&lt;FONT size="4"&gt;what do you see for the variables?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;FONT size="4"&gt;If the variable from the Lifeexpentancy , or any other data set on a SET statement has&amp;nbsp; length of 25 that is the longest value you are going to get even if you redefine the property with a length statement as you have done here.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;FONT size="4"&gt;Consider:&lt;BR /&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;data example;
   somevar = 'Not very long text';
run;

proc contents data=example;
run;

data modified;
   length somevar $ 50;
   set example;
run;

proc contents data=modified;
run;
&lt;/PRE&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;FONT size="4"&gt;The first data set only has 18 characters in the &lt;STRONG&gt;value&lt;/STRONG&gt;. So even though I change the property of the variable, and will show in proc contents as longer, there is no information added just because I made the variable longer.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 22:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-string-variable-is-getting-cut-off-despite-having-set/m-p/705212#M216275</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-10T22:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: My string variable is getting cut off despite having set adaquate length, format and informat.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-string-variable-is-getting-cut-off-despite-having-set/m-p/705221#M216283</link>
      <description>&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 18.06px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;Thank you. I did not realize that use of a length statement allow you to redefine length in the case where the longest value is shorter. Sounds like I was trying to put a square in round hole. I think that I have resolved this, though I did so in a way that leaves me with questions. The data set that I was using was from gapminder.org. When I downloaded the xlsx file and ran the program, I received an "exception error". I have seem this before and knew it was an unknown formatting bug that would not let me be successful with that version. Next, I downloaded the csv file. This was the file I was having difficulty with when I posted my question. Once you shared the detail about the limitations of the length statement, I again wondered if it was a formatting issue with the original csv file. I opened it and saved the csv as xlsx (rather than downloading the xlsx from the website). This time my length statement before SET achieved what I wanted it to and there was no more truncation. Experience like this have been accumulating for me. That is, I start with a standard file format, but find it does not behave in a standard way. Thanks again for the length tip! Very helpful.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 00:28:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-string-variable-is-getting-cut-off-despite-having-set/m-p/705221#M216283</guid>
      <dc:creator>ldierker1</dc:creator>
      <dc:date>2020-12-11T00:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: My string variable is getting cut off despite having set adaquate length, format and informat.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-string-variable-is-getting-cut-off-despite-having-set/m-p/705234#M216288</link>
      <description>&lt;P&gt;You've investigated the length of the variable storage.&amp;nbsp; But perhaps the variable value was not read in correctly.&amp;nbsp; So make sure there is a $50 character value in COUNTRY.&amp;nbsp; Do a proc print of the country variable, or open the dataset interactively to examine visually.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 03:30:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-string-variable-is-getting-cut-off-despite-having-set/m-p/705234#M216288</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-12-11T03:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: My string variable is getting cut off despite having set adaquate length, format and informat.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-string-variable-is-getting-cut-off-despite-having-set/m-p/705236#M216289</link>
      <description>&lt;P&gt;If you use PROC IMPORT to read a text file (CSV files are comma delimited text files) it has to GUESS how to define the variables.&amp;nbsp; &amp;nbsp;Plus to save time it will by default only look at the beginning of the file to get information to make its guesses.&amp;nbsp; By saving the file as an XLSX file you ended up using a different method of conversion and show it did not guess the wrong length for that variable.&amp;nbsp; But by opening a CSV file with EXCEL you have now risked having excel convert the values of the data.&amp;nbsp; Excel will be default convert strings that it thinks look like number or dates. So strings like ZIPCODEs that might start with a leading zero will lose the leading zero.&amp;nbsp; And stings that consist of two sets of digits separated by a hyphen might get converted in dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Write your own data step to read the CSV file and you will have full control over how the variables are defined and read.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 04:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-string-variable-is-getting-cut-off-despite-having-set/m-p/705236#M216289</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-11T04:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: My string variable is getting cut off despite having set adaquate length, format and informat.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-string-variable-is-getting-cut-off-despite-having-set/m-p/705238#M216290</link>
      <description>Great advice. Thank you.</description>
      <pubDate>Fri, 11 Dec 2020 05:30:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-string-variable-is-getting-cut-off-despite-having-set/m-p/705238#M216290</guid>
      <dc:creator>ldierker1</dc:creator>
      <dc:date>2020-12-11T05:30:41Z</dc:date>
    </item>
  </channel>
</rss>

