<?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: importing untruncated character variable from csv file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939375#M368828</link>
    <description>&lt;P&gt;&lt;STRONG&gt;NEVER&lt;/STRONG&gt; use PROC IMPORT when you don't have to.&lt;/P&gt;
&lt;P&gt;For csv files, write the DATA step yourself, according to the description/documentation of the file.&lt;/P&gt;
&lt;P&gt;The IMPORT procedure makes guesses, and you regularly end up with incorrect data types and other attributes, which you then have to fix.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Aug 2024 08:08:15 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2024-08-15T08:08:15Z</dc:date>
    <item>
      <title>importing untruncated character variable from csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939333#M368816</link>
      <description>&lt;P&gt;Folks, I need help with importing character variables that do not have truncated values from csv files. Below is my import code and the lenght of the variable I need to reach. Any help with resolving this issue would be much appreciated!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt; &lt;STRONG&gt;IMPORT&lt;/STRONG&gt; OUT= TEST.my_data_2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATAFILE= "C:\testing\drugx\data\rhabdomyo.csv"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DBMS=CSV REPLACE;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GETNAMES=YES;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATAROW=&lt;STRONG&gt;2&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;Variable&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Type&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Len&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Format&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Informat&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;Drugname&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Char&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;13&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;$13.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;$13&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2024 20:44:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939333#M368816</guid>
      <dc:creator>ama220</dc:creator>
      <dc:date>2024-08-14T20:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: Where do I post my question in the SAS Support Communities?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939330#M368829</link>
      <description>&lt;P&gt;Folks, I need help with importing character variables that do not have truncated values from csv files. Below is my import code and the lenght of the variable I need to reach. Any help with resolving this issue would be much appreciated!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt; &lt;STRONG&gt;IMPORT&lt;/STRONG&gt; OUT= TEST.my_data_2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATAFILE= "C:\testing\drugx\data\rhabdomyo.csv"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DBMS=CSV REPLACE;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GETNAMES=YES;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATAROW=&lt;STRONG&gt;2&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;Variable&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Type&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Len&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Format&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Informat&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;Drugname&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Char&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;13&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;$13.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;$13&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2024 20:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939330#M368829</guid>
      <dc:creator>ama220</dc:creator>
      <dc:date>2024-08-14T20:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: importing untruncated character variable from csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939334#M368817</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC IMPORT OUT= TEST.my_data_2
            DATAFILE= "C:\testing\drugx\data\rhabdomyo.csv"
            DBMS=CSV REPLACE;
     GETNAMES=YES;
     DATAROW=2;
    guessingrows = max;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Try GUESSINGROWS.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2024 21:21:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939334#M368817</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2024-08-14T21:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: importing untruncated character variable from csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939336#M368819</link>
      <description>&lt;P&gt;If you know how the variables should be defined why are using PROC IMPORT.&amp;nbsp; That will have to GUESS how to define the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general it is best to write a data step to read a CSV file.&amp;nbsp; That will give you complete control over the variable, NAME, TYPE, storage LENGTH, and whether or not to attach any formats, informats or labels.&amp;nbsp; Note that most variables do not need either FORMAT or INFORMAT attached to them since SAS already knows how to write and read both numeric and character variables.&amp;nbsp; The main exception is DATE, TIME and DATETIME values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2024 22:09:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939336#M368819</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-08-14T22:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: importing untruncated character variable from csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939375#M368828</link>
      <description>&lt;P&gt;&lt;STRONG&gt;NEVER&lt;/STRONG&gt; use PROC IMPORT when you don't have to.&lt;/P&gt;
&lt;P&gt;For csv files, write the DATA step yourself, according to the description/documentation of the file.&lt;/P&gt;
&lt;P&gt;The IMPORT procedure makes guesses, and you regularly end up with incorrect data types and other attributes, which you then have to fix.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2024 08:08:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939375#M368828</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-08-15T08:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: importing untruncated character variable from csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939468#M368862</link>
      <description>&lt;P&gt;Thanks, it worked!&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2024 16:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939468#M368862</guid>
      <dc:creator>ama220</dc:creator>
      <dc:date>2024-08-15T16:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: importing untruncated character variable from csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939469#M368863</link>
      <description>Thanks, it worked!</description>
      <pubDate>Thu, 15 Aug 2024 16:21:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939469#M368863</guid>
      <dc:creator>ama220</dc:creator>
      <dc:date>2024-08-15T16:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: importing untruncated character variable from csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939471#M368864</link>
      <description>Thank you! The file has many variables and I did not wan to list them all in in the input line. Do you know an easy way to do that without having to type them all?</description>
      <pubDate>Thu, 15 Aug 2024 16:27:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939471#M368864</guid>
      <dc:creator>ama220</dc:creator>
      <dc:date>2024-08-15T16:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: importing untruncated character variable from csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939472#M368865</link>
      <description>Thanks!</description>
      <pubDate>Thu, 15 Aug 2024 16:27:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939472#M368865</guid>
      <dc:creator>ama220</dc:creator>
      <dc:date>2024-08-15T16:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: importing untruncated character variable from csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939479#M368868</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83909"&gt;@ama220&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you! The file has many variables and I did not wan to list them all in in the input line. Do you know an easy way to do that without having to type them all?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Copy and paste.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have trouble opening the CSV file in a text editor to get the header row out so you can copy it then let SAS do it for you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile csv dsd obs=1;
  input name :$32. @@;
  put name @;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can copy the names from the SAS log and the commas will have already been removed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have the list of names you can use it to make a LENGTH statement.&amp;nbsp; Just put the length you want after each variable (or group of variables if they all should be the same length).&amp;nbsp; Then the INPUT statement can just use a simple positional variable list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile csv dsd truncover firstobs=2;
  length varfirst $20 var2 var3 var4 8 var5 varlast $10 ;
  input varfirst -- varlast;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have any DATE, TIME or DATETIME values then also add INFORMAT and FORMAT statements for those variables. (Normal numeric and character variables do not need either a format or an informat attached to them.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another possibly is to paste the list into the INPUT statement.&amp;nbsp; You can then add :$xx. after any character variable.&amp;nbsp; If you are happy with making a character variable of length 8 just use bare $ instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile csv dsd truncover firstobs=2 ;
  input varfirst :$20. var2 var3 var4 var5 :$10. varlast :$10. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Aug 2024 17:20:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-untruncated-character-variable-from-csv-file/m-p/939479#M368868</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-08-15T17:20:25Z</dc:date>
    </item>
  </channel>
</rss>

