<?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: droping variables in export to multiple csv files with column headings in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406531#M98992</link>
    <description>&lt;P&gt;Hi again,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get no rows selected when using the dictionary.columns&amp;nbsp; , also I don´t understand what you mean with the&amp;nbsp; /*add csvf here' comment*/ Thanks&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;2266  proc sql noprint;
2267  select name into :varlist1 separated by ' ' from dictionary.columns where libname =
2267! 'WORK' and memname='csv3';
NOTE: No rows were selected.
2268  select name into :varlist2 separated by ',' from dictionary.columns where libname =
2268! 'WORK' and memname='csv3';
NOTE: No rows were selected.
2269  quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 23 Oct 2017 14:02:01 GMT</pubDate>
    <dc:creator>vanmon1</dc:creator>
    <dc:date>2017-10-23T14:02:01Z</dc:date>
    <item>
      <title>droping variables in export to multiple csv files with column headings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406485#M98978</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=csv3;
by csvf;
run;


data _null_;
  set csv3;
  by csvf;
 
  fv = "\\tsclient\C\Transferencia de Archivos\EXPORTED FINAL TABLE\OPORTO\BASTIDORES\LINEA P" ||"_"|| TRIM(put(csvf,$50.)) || ".csv";

  file write filevar=FV dsd  dlm=','  lrecl=32000 ;
  if first.csvf then link names;
  put (_all_) (:) ;
return;

names:
length _name_ $50;
call missing(_name_);do while(1);
call vnext(_name_);
if _name_ eq: 'FIRST.' then leave;
put _name_@;
end;
put;

run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hello, I have managed to export my data set in to multiple csv files by each change in the last variable and with column headings. created this last variable to group and name each of those csv files but I would like to get rid of it&amp;nbsp; inside the csv file. Is this possible?&lt;/P&gt;&lt;P&gt;T&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Current results" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16142iEE1B259B49F1EFAB/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="Current results" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Current results&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Desired result (last variable missing)" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16143i9FA6536DAA5F612A/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="Desired result (last variable missing)" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Desired result (last variable missing)&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 12:24:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406485#M98978</guid>
      <dc:creator>vanmon1</dc:creator>
      <dc:date>2017-10-23T12:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: droping variables in export to multiple csv files with column headings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406487#M98980</link>
      <description>&lt;P&gt;Use the drop= dataset option in the set statement.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 12:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406487#M98980</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-23T12:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: droping variables in export to multiple csv files with column headings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406493#M98983</link>
      <description>&lt;P&gt;Hi KurtBremser,&lt;/P&gt;&lt;P&gt;I´m afraid that does not work because of the way I input the column names using vnext , I think.&lt;/P&gt;&lt;P&gt;Basically it took me a long time to add the column headings and now I cannot drop the variables I don´t need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 12:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406493#M98983</guid>
      <dc:creator>vanmon1</dc:creator>
      <dc:date>2017-10-23T12:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: droping variables in export to multiple csv files with column headings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406497#M98985</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/155644"&gt;@vanmon1&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi KurtBremser,&lt;/P&gt;
&lt;P&gt;I´m afraid that does not work because of the way I input the column names using vnext , I think.&lt;/P&gt;
&lt;P&gt;Basically it took me a long time to add the column headings and now I cannot drop the variables I don´t need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then you have to replace the _all_ with an exhaustive list of the variables you want output, and do similar for the header.&lt;/P&gt;
&lt;P&gt;You could facilitate that by creating a list of variables from dictionary.columns before you add the filename variable, and then use that list to write dynamic code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select name into :varlist1 separated by ' ' from dictionary.columns where libname = 'WORK' and memame = 'CSV3';
select name into :varlist2 separated by ',' from dictionary.columns where libname = 'WORK' and memame = 'CSV3';
quit;

/* add csvf here */

data _null_;
set csv3;
by csvf;
fv = "\\tsclient\C\Transferencia de Archivos\EXPORTED FINAL TABLE\OPORTO\BASTIDORES\LINEA P" ||"_"|| TRIM(put(csvf,$50.)) || ".csv";
file write filevar=fv dsd dlm=',' lrecl=32000;
if first.csvf then put "&amp;amp;varlist2";
put &amp;amp;varlist1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Oct 2017 12:52:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406497#M98985</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-23T12:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: droping variables in export to multiple csv files with column headings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406531#M98992</link>
      <description>&lt;P&gt;Hi again,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get no rows selected when using the dictionary.columns&amp;nbsp; , also I don´t understand what you mean with the&amp;nbsp; /*add csvf here' comment*/ Thanks&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;2266  proc sql noprint;
2267  select name into :varlist1 separated by ' ' from dictionary.columns where libname =
2267! 'WORK' and memname='csv3';
NOTE: No rows were selected.
2268  select name into :varlist2 separated by ',' from dictionary.columns where libname =
2268! 'WORK' and memname='csv3';
NOTE: No rows were selected.
2269  quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Oct 2017 14:02:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406531#M98992</guid>
      <dc:creator>vanmon1</dc:creator>
      <dc:date>2017-10-23T14:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: droping variables in export to multiple csv files with column headings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406536#M98993</link>
      <description>&lt;P&gt;Always write memnames in capitals.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And my comment is the placeholder for "created this last variable to group and name each of those csv files" from your initial post.&lt;/P&gt;
&lt;P&gt;If that variable is there from the beginning, add a suitable condition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select name into :varlist1 separated by ' ' from dictionary.columns where libname = 'WORK' and memname = 'CSV3' and upcase(name) ne 'CSVF';
select name into :varlist2 separated by ',' from dictionary.columns where libname = 'WORK' and memname = 'CSV3' and upcase(name) ne 'CSVF';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;While libnames and memnames are always supplied by SAS in capitals, variable names retain their case.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 14:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406536#M98993</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-23T14:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: droping variables in export to multiple csv files with column headings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406540#M98995</link>
      <description>&lt;P&gt;Now it Works! Thanks very much for your time and patience!&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 14:19:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406540#M98995</guid>
      <dc:creator>vanmon1</dc:creator>
      <dc:date>2017-10-23T14:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: droping variables in export to multiple csv files with column headings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406541#M98996</link>
      <description>&lt;P&gt;Great! Perfect! Thanks very much.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 14:20:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406541#M98996</guid>
      <dc:creator>vanmon1</dc:creator>
      <dc:date>2017-10-23T14:20:51Z</dc:date>
    </item>
    <item>
      <title>Re: droping variables in export to multiple csv files with column headings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406550#M99000</link>
      <description>&lt;P&gt;CSVF is the filename and looks like it was created from values of existing variables .&amp;nbsp; If so you can move the code that creates that string to the DATA _NULL_ step and include in the creation of FV variable.&amp;nbsp; Notice that since FV is the FILEVAR is not included in _ALL_.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show the code that makes CSVF.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 14:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406550#M99000</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-10-23T14:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: droping variables in export to multiple csv files with column headings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406828#M99111</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE FINAL AS 
SELECT 
A.ESTACION as ESTACION, A.LEVEL, A.STATUS, A.VENDOR_CODE, B.PART AS ITEMNUM, A.MOD_LEVEL, A.SERIALNUM, A.DESCRIPTION, A.DERIVED_POSITION, A.BTSUPPLIEREXPDATE,A.PURCHASE_ORDER,A.MANUFACTURER_CODE, 
A.WARRCHECKDATE, a.orden
FROM B15 A JOIN CMITEM3 B ON A.DESCRIPTION=B.DESCITEM;
QUIT;
data csv;
set final;
ocb=substr(serialnum,11,4);
oc=substr(serialnum,11,3);
run;
proc sql;
create table csv2 as select a.*, case when oc like '%%H%%' then a.estacion||b.ocb end as csvf
from final a join csv b on a.serialnum=b.serialnum and a.estacion=b.estacion ;
quit;

data csv3;
   set csv2;
   if orden=2 then comodin=csvf;
   retain comodin;
   if missing(csvf) then csvf= comodin;
   else comodin=csvf;
   drop comodin orden;
run;

proc sort data=csv3;
by csvf;
run;


proc sql noprint; 
select name into :varlist1 separated by ' ' from dictionary.columns where libname = 'WORK' and memname='CSV3' and upcase(name) not in ( 'CSVF','ESTACION');
select name into :varlist2 separated by ',' from dictionary.columns where libname = 'WORK' and memname='CSV3' and upcase(name) not in  ('CSVF','ESTACION');
quit;



data _null_;
set csv3;
by csvf;
fv = "\\tsclient\C\Transferencia de Archivos\EXPORTED FINAL TABLE\OPORTO\BASTIDORES\LINEA P" ||"_"|| TRIM(put(csvf,$50.)) || ".csv";
file write filevar=fv dsd dlm=',' lrecl=32000;
if first.csvf then put "&amp;amp;varlist2";
put &amp;amp;varlist1;
run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hi data _null_ , actually I read some of your posts and found them very useful. Above is my code. Always interesting to learn new ways. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2017 07:23:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/406828#M99111</guid>
      <dc:creator>vanmon1</dc:creator>
      <dc:date>2017-10-24T07:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: droping variables in export to multiple csv files with column headings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/407092#M99172</link>
      <description>&lt;P&gt;If you don't want to print the variable then do not include it in the input dataset. Looks like you are using it to create the variable used on the FILE statement. So&amp;nbsp;create and keep&amp;nbsp;that variable instead.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example using SASHELP.CLASS and using NAME as the grouping variable for generating the filename, but dropping it from the data file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let prefix=c:\downloads\example ;

data toprint ;
  set sashelp.class(obs=3);
  by name ;
  length fv $200 ;
  fv = cats("&amp;amp;prefix._",name,'.csv') ;
  drop name ;
run;

data _null_;
  set toprint ;
  by fv;
  file write filevar=FV lrecl=32000 dsd  dlm=','  ;
  if first.fv then link names;
  put (_all_) (:) ;
return;
names:
 length _name_ $32;
 call missing(_name_);
 do while(1);
   call vnext(_name_);
   if _name_ eq: 'FIRST.' then leave;
   if upcase(_name_) ne 'FV' then put _name_ @;
 end;
 put;
return;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that I had to add extra logic in the subroutine that prints the column headers to prevent it from writing a header for the FV variable.&amp;nbsp; Here you can see the resulting three files that are created.&lt;/P&gt;
&lt;PRE&gt;1324  data _null_;
1325    infile "&amp;amp;prefix._*.csv";
1326    input;
1327    put _infile_;
1328  run;

NOTE: The infile "c:\downloads\example_*.csv" is:
      Filename=c:\downloads\example_Alfred.csv,
      File List=c:\downloads\example_*.csv,RECFM=V,
      LRECL=32767

Sex,Age,Height,Weight
M,14,69,112.5
NOTE: The infile "c:\downloads\example_*.csv" is:
      Filename=c:\downloads\example_Alice.csv,
      File List=c:\downloads\example_*.csv,RECFM=V,
      LRECL=32767

Sex,Age,Height,Weight
F,13,56.5,84
NOTE: The infile "c:\downloads\example_*.csv" is:
      Filename=c:\downloads\example_Barbara.csv,
      File List=c:\downloads\example_*.csv,RECFM=V,
      LRECL=32767

Sex,Age,Height,Weight
F,13,65.3,98
NOTE: 2 records were read from the infile "c:\downloads\example_*.csv".
      The minimum record length was 13.
      The maximum record length was 21.
NOTE: 2 records were read from the infile "c:\downloads\example_*.csv".
      The minimum record length was 12.
      The maximum record length was 21.
NOTE: 2 records were read from the infile "c:\downloads\example_*.csv".
      The minimum record length was 12.
      The maximum record length was 21.
&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Oct 2017 21:56:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/droping-variables-in-export-to-multiple-csv-files-with-column/m-p/407092#M99172</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-24T21:56:08Z</dc:date>
    </item>
  </channel>
</rss>

