<?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: Reverse of PROC CONTENTS to create an Empty Dataset in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315153#M61623</link>
    <description>&lt;P&gt;If you are concerned with overlong character variable lengths and the resulting use of disk space, just use the compress=yes option to minimize the space used by empty character variables.&lt;/P&gt;
&lt;P&gt;Keep in mind that the defined lengths might be needed in the future.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Nov 2016 11:12:03 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-11-29T11:12:03Z</dc:date>
    <item>
      <title>Reverse of PROC CONTENTS to create an Empty Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315143#M61620</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is a&amp;nbsp;reverse of PROC CONTENTS possible to create an EMPTY DATASET.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created a proc contents dataset as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc contents data=EMP&amp;nbsp;out=EMP_OUT noprint;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I updated the LENGTH of few columns in &lt;SPAN&gt;EMP&lt;/SPAN&gt;&lt;SPAN&gt;_OUT &lt;/SPAN&gt;using proc sql.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I like to create the EMPTY DATASET having this updated LENGTHs and the rest of the attributes remain the same.&lt;/P&gt;&lt;P&gt;After that I like to merge the EMPTY DATASET back to the original EMP.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, I am trying to update lengths of&amp;nbsp;each of the variables accoring to its maximum value length in&amp;nbsp;that variable. To reduce the size of the dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 10:49:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315143#M61620</guid>
      <dc:creator>nswaroop</dc:creator>
      <dc:date>2016-11-29T10:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse of PROC CONTENTS to create an Empty Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315145#M61621</link>
      <description>&lt;P&gt;Have you used or tried the DESCRIBE statement in PROC SQL.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 10:52:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315145#M61621</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-29T10:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse of PROC CONTENTS to create an Empty Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315146#M61622</link>
      <description>&lt;P&gt;In your SQL which fixes the length, put a condition which can't be true:&lt;/P&gt;
&lt;PRE&gt;where 1=0;&lt;/PRE&gt;
&lt;P&gt;Then you will have a dataset with 0 observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However it sounds a bit of a pointless task, your not going to save anything in your dataset by reducing the length (unless you talking about 10s of millions of rows - in which case you should be looknig at proper tech for that). &amp;nbsp;Its probably also a bit risky, if your column width is dynamic, then all code after that and based on that data has to be dynamic. &amp;nbsp;Me I prefer nice fixed structures, simpler coding, straight forward documentation, no faffing about.&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>Tue, 29 Nov 2016 10:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315146#M61622</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-29T10:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse of PROC CONTENTS to create an Empty Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315153#M61623</link>
      <description>&lt;P&gt;If you are concerned with overlong character variable lengths and the resulting use of disk space, just use the compress=yes option to minimize the space used by empty character variables.&lt;/P&gt;
&lt;P&gt;Keep in mind that the defined lengths might be needed in the future.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 11:12:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315153#M61623</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-29T11:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse of PROC CONTENTS to create an Empty Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315159#M61624</link>
      <description>&lt;P&gt;You have three steps now: &amp;nbsp;PROC CONTENTS, PROC SQL, and a DATA step to merge. &amp;nbsp;You could do this much more simply in a single DATA step, since you know the names of the variables you want to hange and the lengths you want to assign:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;length name $ 20 address $ 30;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just make sure the LENGTH statement appears before the SET statement.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 11:41:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315159#M61624</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-29T11:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse of PROC CONTENTS to create an Empty Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315212#M61629</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Hits #41 Creating an empty sas datasets (from SAS-L)

Not exactly a reversal of proc contents, but related

/* T000180 CREATING AN EMPTY SAS DATASETS
                              */
   data shell;
       length x 8 name sex $16;
       call missing(of _all_);
       stop;
   run;quit;  /* call missing elims warniing */


   data shell(drop=age);
        stop;
        set sashelp.class sashelp.shoes;
        AgeChar=put(age,z2.);
   run;

   proc sql;
        create table t1(
             id int
            ,ic varchar(10)
            ,icd varchar(500)
            ,Idca varchar(500)
        ) ;
   quit;

   proc sql;
        create
           table new
        like
           sashelp.class;
   quit;

   Also you can create a SAS dataset with data
   (bug introduced after 9.2 - char lengths missing)

   filename tagset http "http://support.sas.com/rnd/base/ods/odsmarkup/sql.sas";
   %include tagset;
   ods tagsets.sql file="class.sql";
   proc print data=sashelp.class ;
   run;
   ods _all_ close;
   ods listing;

   Create table CLASS
   (Name varchar(7), Sex varchar(1), Age float, Height float, Weight float);
   Insert into CLASS(Name, Sex, Age, Height, Weight)
   Values ('Alfred', 'M', 14, 69.0, 112.5);
   Insert into CLASS(Name, Sex, Age, Height, Weight)
   Values ('Alice', 'F', 13, 56.5, 84.0);
   /* Can be simplified */
   Create table CLASS
   (Name varchar(7), Sex varchar(1), Age float, Height float, Weight float);
   Insert into CLASS(Name, Sex, Age, Height, Weight)
   Values ('Alfred', 'M', 14, 69.0, 112.5)
   Values ('Alice', 'F', 13, 56.5, 84.0);


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Nov 2016 15:19:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315212#M61629</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2016-11-29T15:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse of PROC CONTENTS to create an Empty Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315398#M61634</link>
      <description>&lt;P&gt;The DESCRIBE is printing a&amp;nbsp;CREATE TABLE statement with all the columns in&amp;nbsp;the proc contents file. What I need is a CREATE TABLE of the table EMP with new lengths.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 03:42:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315398#M61634</guid>
      <dc:creator>nswaroop</dc:creator>
      <dc:date>2016-11-30T03:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse of PROC CONTENTS to create an Empty Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315401#M61635</link>
      <description>Not sure I understood the solution. But, I am tending to think the requirement is different.&lt;BR /&gt;You are correct that better coding practices but I am beginner to SAS and so...</description>
      <pubDate>Wed, 30 Nov 2016 03:45:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315401#M61635</guid>
      <dc:creator>nswaroop</dc:creator>
      <dc:date>2016-11-30T03:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse of PROC CONTENTS to create an Empty Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315402#M61636</link>
      <description>Compress is okay. This is a requirement of the FDA (clinical domain) to set minimum lengths possible before sending it to them.</description>
      <pubDate>Wed, 30 Nov 2016 03:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315402#M61636</guid>
      <dc:creator>nswaroop</dc:creator>
      <dc:date>2016-11-30T03:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse of PROC CONTENTS to create an Empty Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315403#M61637</link>
      <description>I am trying it automate it in a macro by sending the name of the dataset and getting a return dataset with reduced variable lengths.</description>
      <pubDate>Wed, 30 Nov 2016 03:51:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315403#M61637</guid>
      <dc:creator>nswaroop</dc:creator>
      <dc:date>2016-11-30T03:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse of PROC CONTENTS to create an Empty Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315404#M61638</link>
      <description>&lt;P&gt;Thank you all for your time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From the replies I understand there is no easy way to create a dataset reverse of PROC CONTENTS. So, I am stating my actual purpose in asking.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just send a dataset to a macro and get a return dataset that has reduced varaible lengths according to the maximum length of data in each character column (leaving numeric columns lengths as original).&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 03:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315404#M61638</guid>
      <dc:creator>nswaroop</dc:creator>
      <dc:date>2016-11-30T03:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse of PROC CONTENTS to create an Empty Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315431#M61641</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro reduce_length(dataset);
%let lib=%upcase(%sysfunc(scan(&amp;amp;dataset,1,.)));
%let ds=%upcase(%sysfunc(scan(&amp;amp;dataset,2,.)));

proc sql noprint;
select name into :names separated by ' '
from dictionary.columns
where libname = "&amp;amp;lib" and memname = "&amp;amp;ds" and type = 'char'
;
select length into :lengths separated by ' '
from dictionary.columns
where libname = "&amp;amp;lib" and memname = "&amp;amp;ds" and type = 'char'
;
quit;

%let num_vars=%sysfunc(countw(&amp;amp;names));

data lengths;
set &amp;amp;dataset (keep=&amp;amp;names) end=done;
array vars {*} &amp;amp;names;
array lens {&amp;amp;num_vars} _temporary_
;
do i = 1 to dim(vars);
  lens{i} = max(lens{i},length(vars{i}));
end;
if done
then do;
  do i = 1 to dim(vars);
    __name = vname(vars{i});
    __length = lens{i};
    output;
  end;
end;
keep __name __length;
run;

data _null_;
set lengths end=done;
if _n_ = 1
then do;
  call execute("data work.new_&amp;amp;ds.; length ");
end;
call execute(trim(__name) !! " $" !! trim(put(__length,5.)) !! " ");
if done then call execute("; set &amp;amp;dataset.; run;");
run;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It retrieves the defined lengths from dictionary.columns, then runs a data step with array processing to get the maximum actual lengths, writes them to a dataset, and then creates a data step that sets the new lengths.&lt;/P&gt;
&lt;P&gt;- the order of variables in the resulting dataset will change, as all character variables will move to the left (front).&lt;/P&gt;
&lt;P&gt;- you will get warnings about multiple lengths specified.&lt;/P&gt;
&lt;P&gt;I tried it with sashelp.cars, and it reduced the length of type from 8 to 6.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might consider adding additional macro parameters to specify the output library or similar.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 08:04:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reverse-of-PROC-CONTENTS-to-create-an-Empty-Dataset/m-p/315431#M61641</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-30T08:04:01Z</dc:date>
    </item>
  </channel>
</rss>

