<?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: Reading csv data, var length in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237831#M43633</link>
    <description>&lt;P&gt;It's really just a QC issue. &amp;nbsp;We are to keep the "original" length, but of course that length is going to be different depending on how the data was read. &amp;nbsp;In this case&amp;nbsp;the production version and the QC version don't match. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, thanks, I know I can do post-processing to change it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For our data transfer specs, length is not specified if the data comes in a csv file. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your INPUT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Dec 2015 15:30:50 GMT</pubDate>
    <dc:creator>evp000</dc:creator>
    <dc:date>2015-12-04T15:30:50Z</dc:date>
    <item>
      <title>Reading csv data, var length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237815#M43626</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Say I have this data in a csv file (&lt;SPAN&gt;C:\Users\xxxx\Desktop\test.csv):&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*&lt;BR /&gt;co11, longstring, col3&lt;BR /&gt;a,one two three four,b&lt;BR /&gt;c,five six seven eight nine,d&lt;BR /&gt;*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I read it with an input statement, I have to specify a length (or informat) but I want it to take&amp;nbsp;the length of the longest value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I use proc import the length is longer than the longest value. &amp;nbsp;Why? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc import datafile = 'C:\Users\xxxx\Desktop\test.csv'&lt;BR /&gt; out = test3&lt;BR /&gt; dbms = csv&lt;BR /&gt; replace;&lt;BR /&gt; getnames = yes;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc print; run;&lt;BR /&gt;proc contents; run; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/* length = 15 */&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt; select max(length(longstring)) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* = 14 */&amp;nbsp;&lt;BR /&gt; from test3;&lt;BR /&gt;quit; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How would I read it so that the length is 14? &amp;nbsp;I've tested this on other data too, where the longest value is 24 and the length created is 26.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 14:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237815#M43626</guid>
      <dc:creator>evp000</dc:creator>
      <dc:date>2015-12-04T14:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: Reading csv data, var length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237824#M43628</link>
      <description>&lt;P&gt;Hi, this is an interesting question. However, I was not able to replicate your result. With your sample .csv data I obtain length 25 from both PROC CONTENTS and PROC SQL -- in perfect agreement with the fact that "&lt;SPAN&gt;five six seven eight nine" is a string consisting of 25 characters. (Actually, the names of the second and third variable were prefixed by an underscore due to the leading blanks in the first line of your data.)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 15:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237824#M43628</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-12-04T15:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: Reading csv data, var length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237829#M43631</link>
      <description>&lt;P&gt;Why do you need to make it length of the longest variable out of interest, it really doesn't matter that much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for length of the variable this would of course be defined up front in you Data Transfer Specification agreement which will detail the strcuture of the data being sent, you do have one yes? &amp;nbsp;Take the length from there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not, then you will need to read the file, and then post process it with some logic, howevedo suggest you look at transfer agreements as a better, more robust solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table LENGTHS as
  select "NAME" as NAME,max(length(NAME)) as M from SASHELP.CLASS;
quit;

data _null_;
  set lengths;
  call execute('data want; length '||strip(name)||' $'||strip(put(m,best.))||'.; set sashelp.class; run;');
run;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Dec 2015 15:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237829#M43631</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-12-04T15:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: Reading csv data, var length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237830#M43632</link>
      <description>&lt;P&gt;Thanks for testing it. &amp;nbsp;I had shortened the text when I ran the test, but I put it back to the example and now I&amp;nbsp;get:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;longstring Char 29 $29. $29.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;longest value:&lt;BR /&gt; 25&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I checked for leading or trailing blanks (in notepad) and don't see any.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 15:27:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237830#M43632</guid>
      <dc:creator>evp000</dc:creator>
      <dc:date>2015-12-04T15:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: Reading csv data, var length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237831#M43633</link>
      <description>&lt;P&gt;It's really just a QC issue. &amp;nbsp;We are to keep the "original" length, but of course that length is going to be different depending on how the data was read. &amp;nbsp;In this case&amp;nbsp;the production version and the QC version don't match. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, thanks, I know I can do post-processing to change it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For our data transfer specs, length is not specified if the data comes in a csv file. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your INPUT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 15:30:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237831#M43633</guid>
      <dc:creator>evp000</dc:creator>
      <dc:date>2015-12-04T15:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: Reading csv data, var length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237832#M43634</link>
      <description>&lt;P&gt;Can you perhaps attach the small sample .csv file, so that we can check if the same discrepancies occur using our SAS installations?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 15:39:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237832#M43634</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-12-04T15:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: Reading csv data, var length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237833#M43635</link>
      <description>&lt;P&gt;Here it is. &amp;nbsp;change the 'txt' back to 'csv'.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again for checking.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 15:44:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237833#M43635</guid>
      <dc:creator>evp000</dc:creator>
      <dc:date>2015-12-04T15:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: Reading csv data, var length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237836#M43636</link>
      <description>&lt;P&gt;Thanks for providing the file. Using your PROC IMPORT code I still get length 25 in both cases:&lt;/P&gt;
&lt;P&gt;longstring Char 25 $25. $25.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have also opened the file with a hex editor and haven't found anything suspicious.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, I retyped the file with&amp;nbsp;Notepad and compared it to your file with a comparison tool and found no difference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, it's still a mystery to me what happened on your side.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 16:02:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237836#M43636</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-12-04T16:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: Reading csv data, var length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237838#M43637</link>
      <description>&lt;P&gt;Just an idea: Could it be a DBCS issue?&lt;/P&gt;
&lt;P&gt;What do you get from&amp;nbsp;&lt;FONT face="courier new,courier"&gt;%put %sysfunc(getoption(dbcs));&lt;/FONT&gt; ?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 16:13:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237838#M43637</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-12-04T16:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: Reading csv data, var length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237839#M43638</link>
      <description>&lt;P&gt;Ok, thanks for trying it out.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 16:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237839#M43638</guid>
      <dc:creator>evp000</dc:creator>
      <dc:date>2015-12-04T16:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: Reading csv data, var length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237840#M43639</link>
      <description>&lt;P&gt;NODBCS&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 16:15:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237840#M43639</guid>
      <dc:creator>evp000</dc:creator>
      <dc:date>2015-12-04T16:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: Reading csv data, var length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237845#M43640</link>
      <description>&lt;P&gt;Ok, thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;When you provided the sample file you wrote "change the 'txt' back to 'csv'". This sounds to me as if the file you attached was not the original .csv file from your PROC IMPORT experiment. And this, in turn, would obviously open the possibility that some strange characterisic of the .csv file got lost in the process of "converting" it to a .txt file. How did you create the .txt from the .csv file?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 16:28:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237845#M43640</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-12-04T16:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: Reading csv data, var length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237849#M43641</link>
      <description>&lt;P&gt;I just copied the file and renamed it with the txt extension, since you can't attach csv files.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 16:33:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237849#M43641</guid>
      <dc:creator>evp000</dc:creator>
      <dc:date>2015-12-04T16:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: Reading csv data, var length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237850#M43642</link>
      <description>If this is a file that is going to be read across a testing and prod environment it seems worth it to me to write a data step to import the data, rather than rely on Proc Import. &lt;BR /&gt;&lt;BR /&gt;The data step will allow you to specify the lengths as desired. &lt;BR /&gt;&lt;BR /&gt;I think the expectation that PROC IMPORT will produce the same results across different environments is a big assumption and can't be trusted.</description>
      <pubDate>Fri, 04 Dec 2015 16:34:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237850#M43642</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-04T16:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: Reading csv data, var length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237851#M43643</link>
      <description>&lt;P&gt;Yes, specifying the length is what I'm pushing for. &amp;nbsp;And it would be consistent across projects.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 16:37:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237851#M43643</guid>
      <dc:creator>evp000</dc:creator>
      <dc:date>2015-12-04T16:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: Reading csv data, var length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237867#M43645</link>
      <description>&lt;P&gt;Indeed, for a quick look into a .csv file with SAS, the IMPORT procedure is convenient. It can also generate a code template for an import data step. But when used for production purposes, those convenient automatisms constitute a risk. From a QC point of view, a procedure statement called "GUESSINGROWS" should make the alarm bells ring.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Still, I am&amp;nbsp;curious about the reason of those length discrepancies. If I were to track that down, I would reduce/increase the actual length of the affected string, in order to find out exactly where the discrepancies start. Then I would make other small modifications to the file, and so on.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 17:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237867#M43645</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-12-04T17:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: Reading csv data, var length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237873#M43646</link>
      <description>&lt;P&gt;Proc Import should have created a datastep program visible in the Log. Copy that to the editor and modify to you hearts content, especially the informats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course if your example file doesn't contain something the length of the longest value that will ever appear (specification document!!) then there can be issues with reusing the code.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 18:41:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-csv-data-var-length/m-p/237873#M43646</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-12-04T18:41:00Z</dc:date>
    </item>
  </channel>
</rss>

