LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2011, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sat, 24 Sep 2011 15:04:40 -0400
Reply-To:     Arthur Tabachneck <art297@ROGERS.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Arthur Tabachneck <art297@ROGERS.COM>
Subject:      Re: When using length statement doesn't change format width
Comments: To: "Duell, Bob" <bd9439@ATT.COM>

Bob,

Thanks for the response, and I don't disagree with your recommended approach, but the behavior is not that definitive. In fact, it highlights a rather major (in my opinion) error in the system.

If you run the following code and, after each of the datasteps, bring up the file in SAS Explorer, I think that you will see what I mean.

data test; length name $30; set sashelp.class; run; proc contents data=test details fmtlen out=out1; run; data test; format name $30.; set sashelp.class; run; proc contents data=test details fmtlen out=out2; run;

If you open file test after the first datastep you will see that name is shown to have a length of 30 and a format of $30. Out1, on the other hand, shows that ONLY the length was set and that no format was assigned.

If you open file test after the second datastep you will see that name again is shown to have a length of 30 and a format of $30. Out2, similarly, shows that BOTH the length was set and that a $30. format was assigned.

As a non-programmer I have always relied on the method of bringing up a file with SAS Explorer, right clicking on a particular variable, and selecting column attributes. If one does that after having run the first datastep, they will see that length is shown as 30, and both the format and informat are shown as being $30.

Either proc contents is showing the wrong information, or the SAS Explorer is showing the wrong information. I don't know which is correct but, if one also changes one of the names to being a longer name, I'm led to think that proc contents is the one showing the incorrect values. E.g., if you run:

data test; length name $30; set sashelp.class; if _n_ eq 3 then name= "FirstName MI VeryLongLastName"; run; proc contents data=test details fmtlen out=out3; run;

the same contradictory results are seen from the two methods (i.e., SAS Explorer and proc contents), but the full name is shown in SAS Explorer and, if you then run a proc print, the full name is also displayed.

Art ------ On Sat, 24 Sep 2011 16:50:58 +0000, DUELL, BOB <bd9439@ATT.COM> wrote:

>Hi Art, > >I don't know of any documentation that describes this behavior exactly as you describe, but it is expected. There are four different attributes associated with each SAS variable (LENGTH, FORMAT, INFORMAT, and LABEL) and each has a corresponding SAS statement that can be used to change the attribute. In other words, using the LENGTH statement only changes the length, it does not affect the other attributes. > >For this reason, I almost always use the ATTRIB statement to define "production" SAS variables in each data set. The ATTRIB statement allows one to define all the attributes at once. For my very formal jobs (for each permanent SAS dataset going to a "production" library), I follow up the section of ATTRIB statements with a KEEP statement; although it does require a bunch of typing, it serves as very good in-code documentation. And the KEEP statement lets me use any other "temporary" variables in the code without them showing up in my production data. > >I don't believe that using a LENGTH statement has ever simultaneously changed the variable format. Note that the FORMAT attribute is optional. My guess is that when you changed a variable length in the past and thought the format length had also changed, it was because the variable did not have any format specification to begin with. I could be wrong historically (perhaps it did so in a previous SAS release). > >Hope this helps, > >Bob > >-----Original Message----- >From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Arthur Tabachneck >Sent: Saturday, September 24, 2011 7:16 AM >To: SAS-L@LISTSERV.UGA.EDU >Subject: When using length statement doesn't change format width > >Can someone point me to documentation that talks about when using a length >statement, before a set statement in a data step, doesn't change the width of >the format statement? > >My experience has always been that using a length statement to change the >width of a character variable results in simultaneously changing the width of >the format. However, I came across a case yesterday where that didn't hold. >Using a format statement, though, ended up changing both. > >Is that particular behavior documented somewhere? > >Thanks in advance, >Art


Back to: Top of message | Previous page | Main SAS-L page