In theory VARCHAR and CHAR differ in the SQL table or expression that a SQL SELECT statement yields; when written to a SAS dataset, they would define the same result. The length specification in SAS SQL changes the default maximum length of a SAS variable from 8 to another number.
Note that the maximum length of a variable limits the length of any value subsequently inserted or updated into that variable. This anticipated maximum length typically has more importance than the maximum length of values in data used to create a SAS dataset initially. Setting the maximum length too low may lead to truncations.
Joe's suggested use of safe variable lengths and the COMPRESS option seems as close to RDBMS methods as anything that one could do in a SAS program. A bit less convenient, but effective for comments and the like when separated into special datasets linked to other datasets ....
S
-----Original Message-----
From: Wensui Liu [mailto:liuwensui@gmail.com]
Sent: Saturday, January 02, 2010 1:01 AM
To: Sigurd Hermansen
Cc: SAS-L@LISTSERV.UGA.EDU
Subject: Re: does sas support varchar data type?
in this case, then what's the difference between varchar and char?
On Sat, Jan 2, 2010 at 12:45 AM, Sigurd Hermansen <HERMANS1@westat.com> wrote:
> Wensui:
> Not to answer for Art, but try
> CREATE TABLE test(TEXT varchar 50);
>
> The length 50 could be set to a much larger value if required.
> S
>
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Wensui Liu
> Sent: Friday, January 01, 2010 11:33 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: does sas support varchar data type?
>
> as always, thank you so much, art!
> see the following code. is there a generic way to read the full string
> into table without specify the length?
>
> proc sql;
> CREATE TABLE test(TEXT varchar);
> insert into test values ('1234567890');
> quit;
>
> On Fri, Jan 1, 2010 at 11:20 PM, Arthur Tabachneck <art297@netscape.net> wrote:
>> Wensui,
>>
>> Take a look at:
>> http://books.google.ca/books?
>> id=uZYn6unDVtoC&pg=PT688&lpg=PT688&dq=sas+equivalent+varchar&source=bl&ots=r
>> 0a99KO47m&sig=6o_TIGSeiCe5-YdGy5-qnAcKqsw&hl=en&ei=lcg-
>> S6vdLszJlAfJu8yjBw&sa=X&oi=book_result&ct=result&resnum=2&ved=0CA4Q6AEwAQ#v=
>> onepage&q=sas%20equivalent%20varchar&f=false
>>
>> or, in short form: http://xrl.us/bgrsyh
>>
>> Art
>> -------
>> On Fri, 1 Jan 2010 22:46:44 -0500, Wensui Liu <liuwensui@GMAIL.COM> wrote:
>>
>>>joe
>>>varchar is character data type of indeterminate length. try this
>>>proc sql;
>>>create table test(TEXT varchar);
>>>insert into test values('1234567890');
>>>quit;
>>>
>>>
>>>On Fri, Jan 1, 2010 at 10:40 PM, Joe Matise <snoopy369@gmail.com> wrote:
>>>> VARCHAR is a SQL data type. SAS has character variables, just not called
>>>> VARCHAR. If you're noting that SAS doesn't have variable length
>> characters,
>>>> look at COMPRESS dataset/system option; make your characters long enough,
>>>> and then COMPRESS will make the space that wasn't being used go away.
>> SAS
>>>> doesn't natively do this, presumably for reasons of simplicity of storage
>>>> [knowing how big each row is ahead of time allows it to specify how much
>>>> storage space to use].
>>>>
>>>> -Joe
>>>>
>>>> On Fri, Jan 1, 2010 at 9:31 PM, Wensui Liu <liuwensui@gmail.com> wrote:
>>>>>
>>>>> i couldn't find any evidence that sas/base supports varchar data type.
>>>>> a little surprise though.
>>>>> any insight or experience?
>>>>>
>>>>> thank you so much and have a happy 2010!
>>>>
>>>>
>>>
>>>
>>>
>>>--
>>>==============================
>>>WenSui Liu
>>>Blog : statcompute.spaces.live.com
>>>Tough Times Never Last. But Tough People Do. - Robert Schuller
>>>==============================
>>
>
>
>
> --
> ==============================
> WenSui Liu
> Blog : statcompute.spaces.live.com
> Tough Times Never Last. But Tough People Do. - Robert Schuller
> ==============================
>
--
==============================
WenSui Liu
Blog : statcompute.spaces.live.com
Tough Times Never Last. But Tough People Do. - Robert Schuller
==============================
|
|
0
|
|
|
|
Reply
|
HERMANS1
|
1/2/2010 6:21:50 PM |
|
On Jan 2, 10:21=A0am, HERMA...@WESTAT.COM (Sigurd Hermansen) wrote:
> In theory VARCHAR and CHAR differ in the SQL table or expression that a S=
QL SELECT statement yields; when written to a SAS dataset, they would defin=
e the same result. The length specification in SAS SQL changes the default =
maximum length of a SAS variable from 8 to another number.
>
> Note that the maximum length of a variable limits the length of any value=
subsequently inserted or updated into that variable. This anticipated maxi=
mum length typically has more importance than the maximum length of values =
in data used to create a SAS dataset initially. Setting the maximum length =
too low may lead to truncations.
>
> Joe's suggested use of safe variable lengths and the COMPRESS option seem=
s as close to RDBMS methods as anything that one could do in a SAS program.=
A bit less convenient, but effective for comments and the like when separa=
ted into special datasets linked to other datasets ....
> S
>
>
>
> -----Original Message-----
> From: Wensui Liu [mailto:liuwen...@gmail.com]
> Sent: Saturday, January 02, 2010 1:01 AM
> To: Sigurd Hermansen
>
> Cc: SA...@LISTSERV.UGA.EDU
> Subject: Re: does sas support varchar data type?
>
> in this case, then what's the difference between varchar and char?
>
> On Sat, Jan 2, 2010 at 12:45 AM, Sigurd Hermansen <HERMA...@westat.com> w=
rote:
> > Wensui:
> > Not to answer for Art, but try
> > CREATE TABLE test(TEXT varchar 50);
>
> > The length 50 could be set to a much larger value if required.
> > S
>
> > -----Original Message-----
> > From: SAS(r) Discussion [mailto:SA...@LISTSERV.UGA.EDU] On Behalf Of We=
nsui Liu
> > Sent: Friday, January 01, 2010 11:33 PM
> > To: SA...@LISTSERV.UGA.EDU
> > Subject: Re: does sas support varchar data type?
>
> > as always, thank you so much, art!
> > see the following code. is there a generic way to read the full string
> > into table without specify the length?
>
> > proc sql;
> > CREATE TABLE test(TEXT varchar);
> > insert into test values ('1234567890');
> > quit;
>
> > On Fri, Jan 1, 2010 at 11:20 PM, Arthur Tabachneck <art...@netscape.net=
> wrote:
> >> Wensui,
>
> >> Take a look at:
> >>http://books.google.ca/books?
> >> id=3DuZYn6unDVtoC&pg=3DPT688&lpg=3DPT688&dq=3Dsas+equivalent+varchar&s=
ource=3Dbl&ots=3D=ADr
> >> 0a99KO47m&sig=3D6o_TIGSeiCe5-YdGy5-qnAcKqsw&hl=3Den&ei=3Dlcg-
> >> S6vdLszJlAfJu8yjBw&sa=3DX&oi=3Dbook_result&ct=3Dresult&resnum=3D2&ved=
=3D0CA4Q6AEwAQ#v=AD=3D
> >> onepage&q=3Dsas%20equivalent%20varchar&f=3Dfalse
>
> >> or, in short form:http://xrl.us/bgrsyh
>
> >> Art
> >> -------
> >> On Fri, 1 Jan 2010 22:46:44 -0500, Wensui Liu <liuwen...@GMAIL.COM> wr=
ote:
>
> >>>joe
> >>>varchar is character data type of indeterminate length. try this
> >>>proc sql;
> >>>create table test(TEXT varchar);
> >>>insert into test values('1234567890');
> >>>quit;
>
> >>>On Fri, Jan 1, 2010 at 10:40 PM, Joe Matise <snoopy...@gmail.com> wrot=
e:
> >>>> VARCHAR is a SQL data type. =A0SAS has character variables, just not=
called
> >>>> VARCHAR. =A0If you're noting that SAS doesn't have variable length
> >> characters,
> >>>> look at COMPRESS dataset/system option; make your characters long en=
ough,
> >>>> and then COMPRESS will make the space that wasn't being used go away=
..
> >> SAS
> >>>> doesn't natively do this, presumably for reasons of simplicity of st=
orage
> >>>> [knowing how big each row is ahead of time allows it to specify how =
much
> >>>> storage space to use].
>
> >>>> -Joe
>
> >>>> On Fri, Jan 1, 2010 at 9:31 PM, Wensui Liu <liuwen...@gmail.com> wro=
te:
>
> >>>>> i couldn't find any evidence that sas/base supports varchar data ty=
pe.
> >>>>> a little surprise though.
> >>>>> any insight or experience?
>
> >>>>> thank you so much and have a happy 2010!
>
> >>>--
> >>>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D
> >>>WenSui Liu
> >>>Blog =A0 : statcompute.spaces.live.com
> >>>Tough Times Never Last. But Tough People Do. =A0- Robert Schuller
> >>>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D
>
> > --
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D
> > WenSui Liu
> > Blog =A0 : statcompute.spaces.live.com
> > Tough Times Never Last. But Tough People Do. =A0- Robert Schuller
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D
>
> --
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D
> WenSui Liu
> Blog =A0 : statcompute.spaces.live.com
> Tough Times Never Last. But Tough People Do. =A0- Robert Schuller
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D- Hide quoted text -
>
> - Show quoted text -
A little off topic
SAS uses compression effectively to save storage. In fact it can
outperform non
compressed varchar in some situations consider the almost 85%
compression of numeric variables and
97% compression of character data.
40619 data Bit(compress=3Dbinary);
40620 retain x1-x10000 0;
40621 drop Idx Jdx;
40622 array Wyd[*] X1-X10000;
40623 do Idx=3D1 to 2;
40624 do Jdx=3D1 to 10000;
40625 Wyd[Jdx]=3Dmod(Jdx,2);
40626 output;
40627 end;
40628 end;
40629 run;
NOTE: The data set WORK.BIT has 20000 observations and 10000
variables.
NOTE: Compressing data set WORK.BIT decreased size by 84.71 percent.
Compressed is 3059 pages; un-compressed would require 20011
pages.
NOTE: DATA statement used (Total process time):
real time 14.45 seconds
cpu time 4.67 seconds
I think SAS uses multiple byte compression for character data
40757 data Chr(compress=3Dchar reuse=3Dyes);
40758 drop Idx Jdx;
40759 array Wyd[*] $3000 X1-X1000;
40760 do Idx=3D1 to 30;
40761 do Jdx=3D1 to 1000;
40762 Wyd[Jdx]=3Drepeat('A',2999);
40763 end;
40764 output;
40765 end;
40766 run;
NOTE: The data set WORK.CHR has 30 observations and 1000 variables.
NOTE: Compressing data set WORK.CHR decreased size by 96.67 percent.
Compressed is 1 pages; un-compressed would require 30 pages.
NOTE: DATA statement used (Total process time):
real time 0.32 seconds
cpu time 0.24 seconds
|
|
0
|
|
|
|
Reply
|
xlr82sas
|
1/3/2010 5:52:12 AM
|
|
|
1 Replies
404 Views
(page loaded in 0.002 seconds)
|