<?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: Copy dataset and keep/drop variables without reading data into memory (no datastep, no proc sort in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-and-keep-drop-variables-without-reading-data-into/m-p/857590#M338858</link>
    <description>&lt;P&gt;Nice point - I haven't thought about views.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However I am hoping to find a binary answer like&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You can (copy and) filter a dataset using to limit variables in a dataset&amp;nbsp;&lt;STRONG&gt;without having to read the dataset into memory&lt;/STRONG&gt; (and without using views) and here is how it goes...&lt;/LI&gt;
&lt;LI&gt;You cannot do that, no way. If you want to change the variables in a dataset you must use a kind of datastep/ SQL statement/ etc. to accomplish this.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I look for this kind of confirmation/ correction in my question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p1juxu16zautpxn1dikxecc3kn7w.htm" target="_self"&gt;&lt;STRONG&gt;proc datasets&lt;/STRONG&gt;&lt;/A&gt; procedure I know that the&amp;nbsp;&lt;STRONG&gt;copy&lt;/STRONG&gt; option&amp;nbsp;&lt;STRONG&gt;does not support data set options&lt;/STRONG&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The same applies to the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p04y85z9f13uaan10s1k40ptx6gs.htm" target="_self"&gt;&lt;STRONG&gt;proc copy&lt;/STRONG&gt;&lt;/A&gt; procedure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As we have the metadata in the dictionaries I was thinking there should be a way of copying a dataset&amp;nbsp;&lt;STRONG&gt;and&lt;/STRONG&gt; use filtering methods (&lt;EM&gt;keep&lt;/EM&gt;/&amp;nbsp;&lt;EM&gt;drop&lt;/EM&gt;) on a higher level than actually reading the whole data.&lt;/P&gt;</description>
    <pubDate>Tue, 07 Feb 2023 16:30:53 GMT</pubDate>
    <dc:creator>left</dc:creator>
    <dc:date>2023-02-07T16:30:53Z</dc:date>
    <item>
      <title>Copy dataset and keep/drop variables without reading data into memory (no datastep, no proc sort)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-and-keep-drop-variables-without-reading-data-into/m-p/857563#M338840</link>
      <description>&lt;P&gt;Is there a way to&amp;nbsp;&lt;STRONG&gt;keep&lt;/STRONG&gt; or&amp;nbsp;&lt;STRONG&gt;drop&lt;/STRONG&gt; variables from a dataset&amp;nbsp;&lt;STRONG&gt;without&lt;/STRONG&gt; using a&amp;nbsp;&lt;STRONG&gt;datastep&lt;/STRONG&gt;?&lt;/P&gt;
&lt;P&gt;Let's assume I know I have a dataset (might be huge) and want to copy it to a new location with just a few variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How would I do this most efficiently, i.e. using minimal computing ressources?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc copy in      = sashelp
          out     = work
          memtype = data;
    select cars;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That will copy all variables, so in this case&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="left_0-1675781129658.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80170i7624164F05D958EE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="left_0-1675781129658.png" alt="left_0-1675781129658.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Variable list as text:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;Make&lt;/TD&gt;
&lt;TD width="20%"&gt;Origin&lt;/TD&gt;
&lt;TD width="20%"&gt;Invoice&lt;/TD&gt;
&lt;TD width="20%"&gt;
&lt;P&gt;Horsepower&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="20%"&gt;Weight&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;Model&lt;/TD&gt;
&lt;TD width="20%"&gt;DriveTrain&lt;/TD&gt;
&lt;TD width="20%"&gt;
&lt;P&gt;EngineSize&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="20%"&gt;MPG_City&lt;/TD&gt;
&lt;TD width="20%"&gt;Wheelbase&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;Type&lt;/TD&gt;
&lt;TD width="20%"&gt;MSRP&lt;/TD&gt;
&lt;TD width="20%"&gt;
&lt;P&gt;Cylinders&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="20%"&gt;MPG_Highway&lt;/TD&gt;
&lt;TD width="20%"&gt;Length&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Usually I would do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cars_few_vars;
    set cars (keep = make model mpg_city);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Without creating a new dataset I can think of this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = cars (keep = make model mpg_city);
    by make;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I think it should be possible to work on a higher level than reading the dataset into memory (datastep, proc sort).&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 14:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-and-keep-drop-variables-without-reading-data-into/m-p/857563#M338840</guid>
      <dc:creator>left</dc:creator>
      <dc:date>2023-02-07T14:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: Copy dataset and keep/drop variables without reading data into memory (no datastep, no proc sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-and-keep-drop-variables-without-reading-data-into/m-p/857571#M338843</link>
      <description>&lt;P&gt;I'm not sure you will see any savings, but you might.&amp;nbsp; Test using a view:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname somewhere 'path to destination';

data cars / view=cars;
   set sashelp.cars (keep=make model mpg_city);
run;
proc copy in      = work
          out     = somewhere;
    select cars;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(Wish I could test it for you but I can't.)&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 15:45:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-and-keep-drop-variables-without-reading-data-into/m-p/857571#M338843</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-02-07T15:45:02Z</dc:date>
    </item>
    <item>
      <title>Re: Copy dataset and keep/drop variables without reading data into memory (no datastep, no proc sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-and-keep-drop-variables-without-reading-data-into/m-p/857590#M338858</link>
      <description>&lt;P&gt;Nice point - I haven't thought about views.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However I am hoping to find a binary answer like&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You can (copy and) filter a dataset using to limit variables in a dataset&amp;nbsp;&lt;STRONG&gt;without having to read the dataset into memory&lt;/STRONG&gt; (and without using views) and here is how it goes...&lt;/LI&gt;
&lt;LI&gt;You cannot do that, no way. If you want to change the variables in a dataset you must use a kind of datastep/ SQL statement/ etc. to accomplish this.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I look for this kind of confirmation/ correction in my question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p1juxu16zautpxn1dikxecc3kn7w.htm" target="_self"&gt;&lt;STRONG&gt;proc datasets&lt;/STRONG&gt;&lt;/A&gt; procedure I know that the&amp;nbsp;&lt;STRONG&gt;copy&lt;/STRONG&gt; option&amp;nbsp;&lt;STRONG&gt;does not support data set options&lt;/STRONG&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The same applies to the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p04y85z9f13uaan10s1k40ptx6gs.htm" target="_self"&gt;&lt;STRONG&gt;proc copy&lt;/STRONG&gt;&lt;/A&gt; procedure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As we have the metadata in the dictionaries I was thinking there should be a way of copying a dataset&amp;nbsp;&lt;STRONG&gt;and&lt;/STRONG&gt; use filtering methods (&lt;EM&gt;keep&lt;/EM&gt;/&amp;nbsp;&lt;EM&gt;drop&lt;/EM&gt;) on a higher level than actually reading the whole data.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 16:30:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-and-keep-drop-variables-without-reading-data-into/m-p/857590#M338858</guid>
      <dc:creator>left</dc:creator>
      <dc:date>2023-02-07T16:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Copy dataset and keep/drop variables without reading data into memory (no datastep, no proc sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-and-keep-drop-variables-without-reading-data-into/m-p/857608#M338866</link>
      <description>&lt;P&gt;Not sure what you mean about "reading data into memory".&amp;nbsp; SAS does not store datasets in memory.&amp;nbsp; It only stores the observations in memory.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To read a dataset you need to read the whole dataset. Unless you want to skip some observations by using the FIRSTOBS= and/or OBS= (really&amp;nbsp; means lastobs) dataset options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The KEEP= and/or DROP= dataset options are probably the easiest ways to select which variables to copy.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data outds;
  set inds(keep=id var1 var5);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you could also generate a simple PROC SQL select statement to select (and potentially re-order) the variables you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table outds as
  select id,var5,var1
  from inds
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Feb 2023 17:21:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-and-keep-drop-variables-without-reading-data-into/m-p/857608#M338866</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-07T17:21:45Z</dc:date>
    </item>
    <item>
      <title>Re: Copy dataset and keep/drop variables without reading data into memory (no datastep, no proc sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-and-keep-drop-variables-without-reading-data-into/m-p/857612#M338869</link>
      <description>&lt;P&gt;Since datasets are stored one observation after another, with each observation containing all values for all defined variables, you must always read the whole dataset physically, even when only some variables are kept.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To reduce the size of the target dataset, the data step is the most efficient tool; if you need to sort anyway, dataset options are the way to go.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 17:29:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-and-keep-drop-variables-without-reading-data-into/m-p/857612#M338869</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-07T17:29:26Z</dc:date>
    </item>
  </channel>
</rss>

