<?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: Length of variable differs across records in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Length-of-variable-differs-across-records/m-p/21581#M4598</link>
    <description>maggi&lt;BR /&gt;
 &lt;BR /&gt;
at the stage when you don't know what lengths you might find, and you must allow for very wide and narrow values, the system and data set option COMPRESS=YES is just what you need!&lt;BR /&gt;
That allows you to set length for your charcter string variables to $32767.&lt;BR /&gt;
However, the trailing space will be compressed to almost nothing.&lt;BR /&gt;
 &lt;BR /&gt;
good &lt;BR /&gt;
peterC</description>
    <pubDate>Sat, 13 Nov 2010 17:00:35 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2010-11-13T17:00:35Z</dc:date>
    <item>
      <title>Length of variable differs across records</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Length-of-variable-differs-across-records/m-p/21576#M4593</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I am hoping someone will be able to give me a solution to the following problem:&lt;BR /&gt;
&lt;BR /&gt;
I have a dataset that I have to read into Stata. Each record has 47 variables, most of them characters, and are delimited by a tab. The problem is that I have no way to determine the length of each variable, i.e., a character variable x may have length 100 (with embedded spaces) in the first record/observation, but may have length of 250 in another record while only 57 in another record. So, if I assign this variable a length of 250, then SAS will go on reading the data into the same variable in case of a record where the variable was only 50 characters long, for example. &lt;BR /&gt;
&lt;BR /&gt;
The total number of records is more than 350,000 so that it's impossible for me to read in the data observation by observation. &lt;BR /&gt;
&lt;BR /&gt;
Is there any command/option along with the input statement that helps me deal with this problem?&lt;BR /&gt;
&lt;BR /&gt;
Thanks a lot!&lt;BR /&gt;
Maggi</description>
      <pubDate>Sat, 23 Oct 2010 22:02:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Length-of-variable-differs-across-records/m-p/21576#M4593</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-10-23T22:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: Length of variable differs across records</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Length-of-variable-differs-across-records/m-p/21577#M4594</link>
      <description>Hi Maggi&lt;BR /&gt;
&lt;BR /&gt;
I'm now confused. Do you intend to read your raw data with STATA or with SAS?&lt;BR /&gt;
&lt;BR /&gt;
With SAS:&lt;BR /&gt;
There are different styles of how you can read raw data (very well explained in the SAS doc).&lt;BR /&gt;
&lt;BR /&gt;
You need "list input". The SAS code might then look something like this:&lt;BR /&gt;
&lt;BR /&gt;
DATA WORK.testdata;&lt;BR /&gt;
    INFILE 'C:\temp\testdata.txt'&lt;BR /&gt;
        DLM='09'x&lt;BR /&gt;
        Truncover&lt;BR /&gt;
        DSD ;&lt;BR /&gt;
    INPUT&lt;BR /&gt;
        var1 : $CHAR3.&lt;BR /&gt;
        var2 : $CHAR17.&lt;BR /&gt;
        var3 : $CHAR5. ;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
'09'x is the ASCII hex representation for a tab. If your operating system is not Windows then another hex value might be needed.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
If you're using SAS EG then you could also use the SAS import wizard (file/import data). &lt;BR /&gt;
In screen2 choose "Delimited fields" and "Tab"&lt;BR /&gt;
In screen3 possibly modify the variable attributes to what's needed for your data.&lt;BR /&gt;
&lt;BR /&gt;
And last but not least:&lt;BR /&gt;
Strings in your raw data might have different lengths, SAS variables don't. The lenght of your SAS variable must be at minimum the maximum length of the strings you want to read (store in the specific SAS variable).&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Patrick</description>
      <pubDate>Sat, 23 Oct 2010 23:07:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Length-of-variable-differs-across-records/m-p/21577#M4594</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-10-23T23:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: Length of variable differs across records</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Length-of-variable-differs-across-records/m-p/21578#M4595</link>
      <description>Just as Mr.Patrick said.But there is another option 'expandtabs' which can change tab to blank.&lt;BR /&gt;
Use Patrick's code;&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
DATA WORK.testdata;&lt;BR /&gt;
INFILE 'C:\temp\testdata.txt' expandtabs Truncover ;&lt;BR /&gt;
INPUT&lt;BR /&gt;
var1 : $CHAR3.&lt;BR /&gt;
var2 : $CHAR17.&lt;BR /&gt;
var3 : $CHAR5. ;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Ksharp</description>
      <pubDate>Mon, 25 Oct 2010 03:45:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Length-of-variable-differs-across-records/m-p/21578#M4595</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-10-25T03:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: Length of variable differs across records</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Length-of-variable-differs-across-records/m-p/21579#M4596</link>
      <description>Hi Patrick and Ksharp,&lt;BR /&gt;
&lt;BR /&gt;
Sorry, I meant SAS.&lt;BR /&gt;
The problem is that I do not know the length of the variables, their mins or maxs. The variables may be 50 characters in one observation, 150 in another and 390 in another! So there is no sure way of assigning lengths to variables while inputting them.&lt;BR /&gt;
&lt;BR /&gt;
I tried your methods but they are, unfortunately, not working as I need them to work!&lt;BR /&gt;
Any suggestions??&lt;BR /&gt;
Thanks!&lt;BR /&gt;
Maggi</description>
      <pubDate>Fri, 12 Nov 2010 04:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Length-of-variable-differs-across-records/m-p/21579#M4596</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-11-12T04:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: Length of variable differs across records</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Length-of-variable-differs-across-records/m-p/21580#M4597</link>
      <description>Just as you said ,The function lenghtc() would be useful,it returned the length of storage of variable.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
 set sashelp.class;&lt;BR /&gt;
 len_sex=lengthc(sex);&lt;BR /&gt;
 len_name=lengthc(name);&lt;BR /&gt;
 put 'NOTE:' len_sex= /&lt;BR /&gt;
     'NOTE:' len_name=;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Fri, 12 Nov 2010 05:53:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Length-of-variable-differs-across-records/m-p/21580#M4597</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-11-12T05:53:53Z</dc:date>
    </item>
    <item>
      <title>Re: Length of variable differs across records</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Length-of-variable-differs-across-records/m-p/21581#M4598</link>
      <description>maggi&lt;BR /&gt;
 &lt;BR /&gt;
at the stage when you don't know what lengths you might find, and you must allow for very wide and narrow values, the system and data set option COMPRESS=YES is just what you need!&lt;BR /&gt;
That allows you to set length for your charcter string variables to $32767.&lt;BR /&gt;
However, the trailing space will be compressed to almost nothing.&lt;BR /&gt;
 &lt;BR /&gt;
good &lt;BR /&gt;
peterC</description>
      <pubDate>Sat, 13 Nov 2010 17:00:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Length-of-variable-differs-across-records/m-p/21581#M4598</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-11-13T17:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: Length of variable differs across records</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Length-of-variable-differs-across-records/m-p/21582#M4599</link>
      <description>Hi.Misunderstood what your said.&lt;BR /&gt;
Actually . I think Patrick's method can work.But It is hard to decide without your origin data.&lt;BR /&gt;
And Maybe you can use LENGTH statement to solve your problem, which has effect as modifier ' : ' ;&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data temp;&lt;BR /&gt;
 length comment $ 20000;&lt;BR /&gt;
 input id comment $;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 tuieorejejepudf&lt;BR /&gt;
2 diuet&lt;BR /&gt;
3 troerpere&lt;BR /&gt;
4 skjfasiwoewojkfoewroegerelgkerg&lt;BR /&gt;
;run;&lt;BR /&gt;
proc print noobs;run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Tue, 16 Nov 2010 09:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Length-of-variable-differs-across-records/m-p/21582#M4599</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-11-16T09:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: Length of variable differs across records</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Length-of-variable-differs-across-records/m-p/21583#M4600</link>
      <description>Hi.Misunderstood what your said.&lt;BR /&gt;
Actually . I think Patrick's method can work.But It is hard to decide without your origin data.&lt;BR /&gt;
And Maybe you can use LENGTH statement to solve your problem, which has effect as modifier ' : ' ;&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data temp;&lt;BR /&gt;
 length comment $ 20000;&lt;BR /&gt;
 input id comment $;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 tuieorejejepudf&lt;BR /&gt;
2 diuet&lt;BR /&gt;
3 troerpere&lt;BR /&gt;
4 skjfasiwoewojkfoewroegerelgkerg&lt;BR /&gt;
;run;&lt;BR /&gt;
proc print noobs;run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Tue, 16 Nov 2010 09:09:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Length-of-variable-differs-across-records/m-p/21583#M4600</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-11-16T09:09:04Z</dc:date>
    </item>
  </channel>
</rss>

