Date: Mon, 11 May 2009 14:54:26 -0500
Reply-To: Carl Denney <cdenney@HEALTHINFOTECHNICS.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Carl Denney <cdenney@HEALTHINFOTECHNICS.COM>
Subject: Re: Reduce the length of a variable
In-Reply-To: <2210b143-b8fc-41ba-b22d-a3bda8fa9bba@s20g2000vbp.googlegro
ups.com>
Content-Type: text/html; x-AttchRem=yes; charset="us-ascii"
<html>
<body>
<br>
This might be useful for some of us. It's a little macro I wrote to
shrink all the character variables to their minimum size. I got tired of
importing a file and looking at it with fsview only to see one variable
per screen.<br><br>
It allows you to supply the dataset to shrink and guessingrows if the
dataset is large. If the dataset has relatively few rows, you can use
"max" for the guessingrows. You could also modify this to add a
few characters to the length if you use guessingrows and think there
might be some cases where the real length is over the maximum length
found.<br><br>
It also removes any format or informats so that Proc Fsview doesn't
object afterward because the format is longer than the variable
length.<br><br>
The other structural difference is that all character variables are
listed before all numeric variables.<br><br>
<br>
If SAS already has a function to do this, I will feel stupid but will
appreciate it if someone will so inform me.<br><br>
<br><br>
<br>
%macro sset(set2shrink,guessingrows);<br><br>
/*<br>
** sset is short for shrinkset;<br>
** This macro looks at the length of all the character variables in a
dataset and ;<br>
** shortens then to the length of the longest string in that field. This
is useful;<br>
** when proc import brings in a dbf or access file with charvars set at
$200;<br>
*/<br><br>
proc contents noprint data=&set2shrink
out=var_property(where=(type=2));run;<br><br>
proc sort;by varnum;run;<br><br>
data _null_;<br>
set var_property;<br>
file 'c:\varlist.prc';<br>
put '%shrinkvar(' name +(-1) ');';<br>
run;<br><br>
%let string= ;<br><br>
%macro shrinkvar(varname);<br><br>
proc sql;<br>
create view test as<br>
select length(&varname) as varlen<br>
from
&set2shrink.(obs=&guessingrows)<br>
;quit;<br><br>
proc univariate noprint data=test;<br>
var varlen;<br>
output out=result1 max=max;<br>
run;<br><br>
data _null_;<br>
set result1;<br>
new="&varname"||"
$"||left(max);<br>
call symput("new",new);<br>
run;<br><br>
%let string=&string &new;<br><br>
%mend shrinkvar;<br>
%inc 'c:\varlist.prc';<br><br>
data &set2shrink(compress=yes);<br>
length &string;<br>
set &set2shrink;<br>
run;<br><br>
data _null_;<br>
lib=scan("&set2shrink",1);<br>
set=scan("&set2shrink",2);<br>
if set=' ' then
do;set=lib;lib="work";end;<br>
call symput("L",lib);<br>
call symput("S",set);<br>
run;<br><br>
proc datasets NOLIST library=&l; modify &S; format _char_;
informat _char_; run; quit;<br><br>
%mend sset;<br><br>
<br><br>
<br><br>
<br><br>
At 02:09 PM 5/11/2009, Richard A. DeVenezia wrote:<br>
<blockquote type=cite class=cite cite="">On May 11, 2:05 pm, Madhu G
<c2ma...@gmail.com> wrote:<br>
> Hi All,<br>
><br>
> can any body suggest me how can I reduce the size of the
variable.<br>
><br>
> In DI studio I need to map Name1(Char 50) to actual_name (char
30).<br>
><br>
> when I am doing this it was saying target column length is
smaller<br>
> than the source column length.<br>
><br>
> and also<br>
><br>
> one more error..<br>
><br>
> ERROR: Variable has been created as Numeric as well as
charecter.<br>
><br>
> Can any body please suggest how can I overcome these two
errors.<br><br>
Try a SUBSTR transformation ?</blockquote>
<x-sigsep><p></x-sigsep>
<br>
<b>Carl Denney, MSIE<br>
<font size=2>Founder<br>
Health InfoTechnics <br>
210 Jamestown Park, Suite 101, Brentwood, TN 37027<br>
</font><font face="Lucida Console" size=2>615/298-4011</font> <br>
<a href="http://www.healthinfotechnics.com/" eudora="autourl">
http://www.healthinfotechnics.com<br>
</a></b></body>
</html>
|