<?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 how to resize datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-resize-datasets/m-p/542785#M150000</link>
    <description>&lt;P&gt;How to resize sas datasets.&lt;/P&gt;&lt;P&gt;I found a program in sas but it gives errors. one of the error is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings13/206P-2013.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings13/206P-2013.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: File WORK.MAXX_T.DATA does not exist.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May be i am missing something.&amp;nbsp; Any one knows program which does the resizing. please let me know&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro chglen (inp=sl);

	proc contents data = &amp;amp;inp. noprint
		out = charvar (where =(type=2)
		keep = memname name type length label);
	run;

	data charvar2;
		length name1 name2 name3 name4 name5 $100;
		set charvar;
		name1 = trim(name)||'1=length('||trim(name)||')';
		name2 = 'max('||trim(name)||'1) as '||trim(name);
		name3 = trim(name)||'x = '||trim(name);
		name4 = trim(name)||' = '||trim(name)||'x';
		name5 = trim(name)||' $'||strip(put(length, best.));
	run;

	proc sql noprint;
		select trim(name1) into: newvar separated by '; '
			from charvar2;
		select trim(name2) into: maxvar separated by ', '
			from charvar2;
		select trim(name3) into: tname separated by '; '
			from charvar2;
		select trim(name4) into: tnamex separated by '; '
			from charvar2;
		select trim(name) into: cvar separated by ' '
			from charvar2;
		select trim(name)||'x' into: cvarx separated by ' '
			from charvar2;
		select trim(name5) into: cvarlen separated by ' '
			from charvar2;
	quit;

	data varlen;
		set &amp;amp;inp.;
		&amp;amp;newvar;
	run;

	proc sql noprint;
		create table maxx as
			select &amp;amp;maxvar
				from varlen;
	quit;

	data maxx_t2;
		length name6 $100;
		set maxx_t;

		if col1&amp;lt;1 then
			col1=1;
		name6 = trim(name)||' $'||strip(put(col1, best.));
	run;

	proc sql noprint;
		select strip(name6) into: newlen separated by ' '
			from maxx_t2;
	quit;

	data temp (drop = &amp;amp;cvar. );
		length &amp;amp;cvarlen;
		set &amp;amp;inp.;
		&amp;amp;tname.;
	run;

	data newone (drop= &amp;amp;cvarx.);
		length &amp;amp;newlen.;
		set temp;
		&amp;amp;tnamex.;
	run;

%mend chglen;

%chglen;&lt;/PRE&gt;</description>
    <pubDate>Wed, 13 Mar 2019 13:40:37 GMT</pubDate>
    <dc:creator>noda6003</dc:creator>
    <dc:date>2019-03-13T13:40:37Z</dc:date>
    <item>
      <title>how to resize datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resize-datasets/m-p/542785#M150000</link>
      <description>&lt;P&gt;How to resize sas datasets.&lt;/P&gt;&lt;P&gt;I found a program in sas but it gives errors. one of the error is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings13/206P-2013.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings13/206P-2013.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: File WORK.MAXX_T.DATA does not exist.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May be i am missing something.&amp;nbsp; Any one knows program which does the resizing. please let me know&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro chglen (inp=sl);

	proc contents data = &amp;amp;inp. noprint
		out = charvar (where =(type=2)
		keep = memname name type length label);
	run;

	data charvar2;
		length name1 name2 name3 name4 name5 $100;
		set charvar;
		name1 = trim(name)||'1=length('||trim(name)||')';
		name2 = 'max('||trim(name)||'1) as '||trim(name);
		name3 = trim(name)||'x = '||trim(name);
		name4 = trim(name)||' = '||trim(name)||'x';
		name5 = trim(name)||' $'||strip(put(length, best.));
	run;

	proc sql noprint;
		select trim(name1) into: newvar separated by '; '
			from charvar2;
		select trim(name2) into: maxvar separated by ', '
			from charvar2;
		select trim(name3) into: tname separated by '; '
			from charvar2;
		select trim(name4) into: tnamex separated by '; '
			from charvar2;
		select trim(name) into: cvar separated by ' '
			from charvar2;
		select trim(name)||'x' into: cvarx separated by ' '
			from charvar2;
		select trim(name5) into: cvarlen separated by ' '
			from charvar2;
	quit;

	data varlen;
		set &amp;amp;inp.;
		&amp;amp;newvar;
	run;

	proc sql noprint;
		create table maxx as
			select &amp;amp;maxvar
				from varlen;
	quit;

	data maxx_t2;
		length name6 $100;
		set maxx_t;

		if col1&amp;lt;1 then
			col1=1;
		name6 = trim(name)||' $'||strip(put(col1, best.));
	run;

	proc sql noprint;
		select strip(name6) into: newlen separated by ' '
			from maxx_t2;
	quit;

	data temp (drop = &amp;amp;cvar. );
		length &amp;amp;cvarlen;
		set &amp;amp;inp.;
		&amp;amp;tname.;
	run;

	data newone (drop= &amp;amp;cvarx.);
		length &amp;amp;newlen.;
		set temp;
		&amp;amp;tnamex.;
	run;

%mend chglen;

%chglen;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Mar 2019 13:40:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resize-datasets/m-p/542785#M150000</guid>
      <dc:creator>noda6003</dc:creator>
      <dc:date>2019-03-13T13:40:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to resize datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resize-datasets/m-p/542793#M150004</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The message in the log is quite clear : you refer to a dataset MAXX_T which doesn't exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem occurs in the data step that creates maxx_t2 :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data maxx_t2;
		length name6 $100;
		set maxx_t; /* HERE ! */
...
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The preceeding proc sql cretaes a dataset named MAXX. Maybe it is a typo and it should be named MAXX_T.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 14:11:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resize-datasets/m-p/542793#M150004</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-03-13T14:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to resize datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resize-datasets/m-p/542815#M150013</link>
      <description>&lt;P&gt;It still gives errors&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the macro variable "NEWLEN".&lt;BR /&gt;1 . $1&lt;BR /&gt;-&lt;BR /&gt;22&lt;BR /&gt;200&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, ;, DEFAULT, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.&lt;/P&gt;&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 14:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resize-datasets/m-p/542815#M150013</guid>
      <dc:creator>noda6003</dc:creator>
      <dc:date>2019-03-13T14:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to resize datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resize-datasets/m-p/542821#M150016</link>
      <description>&lt;P&gt;I've had good results using the %chg_length macro documented in the sample library: &lt;A href="http://support.sas.com/kb/48/638.html" target="_blank"&gt;http://support.sas.com/kb/48/638.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I use it most often when extracting data from a third party database.&amp;nbsp; It can make a huge performance benefit when you don't need to drag around large character variables.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 15:02:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resize-datasets/m-p/542821#M150016</guid>
      <dc:creator>DaveHorne</dc:creator>
      <dc:date>2019-03-13T15:02:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to resize datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resize-datasets/m-p/542824#M150018</link>
      <description>&lt;P&gt;What do you actually mean by "resize"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want to consider learning to use the various CAT functions instead of the || operator. You can avoid most of the Trim() calls using CATS:&lt;/P&gt;
&lt;PRE&gt;data charvar2;
   length name1 name2 name3 name4 name5 $100;
   set charvar;
   name1 = cats(name),'1=length(',name),')');
   name2 = cats('max(',name,'1) as ',name);&lt;BR /&gt;   name5 = cats('name,' $',length);&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;CATS, CATT , CATX, CATQ and CAT all will automatically use the best. format to convert numeric values.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 15:08:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resize-datasets/m-p/542824#M150018</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-13T15:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to resize datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resize-datasets/m-p/542871#M150052</link>
      <description>&lt;P&gt;This program seems overly complicated and i can't really figure out what it does by just reading it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the goal is just to modify the length of character columns to the minimal length that avoids truncation,&lt;/P&gt;
&lt;P&gt;you can try the following macro :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro resize(lib=sashelp, mem=class, out=&amp;amp;mem.);

    proc sql noprint;
        /* We get the list of charcter columns */
        SELECT NAME
        INTO :CHARCOLS SEPARATED BY ' '
        FROM dictionary.columns
        WHERE LIBNAME=upcase("&amp;amp;lib.") AND MEMNAME=upcase("&amp;amp;mem.")
        AND upcase(TYPE)="CHAR";

        /* For each char column we get the minimum length that avoids truncation */
        /* Ex: "var1 $5. var2 $7. ..."                                           */
        %let nchars=%sysfunc(countw(&amp;amp;CHARCOLS));

        SELECT DISTINCT cat(
        %do i=1 %to &amp;amp;nchars.;
            %let col=%scan(&amp;amp;CHARCOLS.,&amp;amp;i.,' ');
            " &amp;amp;col. $",max(length(&amp;amp;col.)),".",
        %end;
        "") /* "" for the last comma */
        INTO :lengths SEPARATED BY ' '
        FROM &amp;amp;lib..&amp;amp;mem.;
    quit;

    /* New dataset with resized char columns */
    data &amp;amp;out.;
        length &amp;amp;lengths.;
        set &amp;amp;lib..&amp;amp;mem.;

    run;

%mend resize;

%resize;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Mar 2019 16:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resize-datasets/m-p/542871#M150052</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-03-13T16:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to resize datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resize-datasets/m-p/542923#M150062</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240711"&gt;@noda6003&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Long character variables has always been a problem i SAS, and setting new lengths based on an analysis of actual data is dangerous, because next day's actual data might be longer. Some variables have content with a defined max. length, like a postal code or social security number, and for these the length can be set safely.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But give ample space to varying-length text, e.g. use 200 if actual data says 157. Consider compressing your SAS data with compress=char, if your concern is disk space.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An easy way to find the lengths in actual data is to export the troublesome variables to csv and import them to a work data set:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length name1 name2 name3 $1024;
	name1 = 'Tom'; name2 = 'W.'; name3 = 'Jones';
run;

filename csvfile "%sysfunc(getoption(work))\w.csv";
proc export data=have outfile=csvfile dbms=csv replace;
run;
proc import datafile=csvfile out=want dbms=csv replace;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="lengths.gif" style="width: 251px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/27911i513163C9E2088BB8/image-size/large?v=v2&amp;amp;px=999" role="button" title="lengths.gif" alt="lengths.gif" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 19:20:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resize-datasets/m-p/542923#M150062</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-03-13T19:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: how to resize datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-resize-datasets/m-p/542926#M150063</link>
      <description>&lt;P&gt;What is the purpose of resizing your SAS datasets? If it is just to save space then it is a whole lot easier to use the SAS option COMPRESS = YES or COMPRESS = BINARY. We have the compression option set permanently to BINARY on our SAS installations and it works extremely well.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 19:25:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-resize-datasets/m-p/542926#M150063</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-03-13T19:25:18Z</dc:date>
    </item>
  </channel>
</rss>

