<?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: Retaining label from csv import in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retaining-label-from-csv-import/m-p/708245#M217620</link>
    <description>&lt;P&gt;Take the data step from the log and adapt it as needed.&lt;/P&gt;
&lt;P&gt;Even better, do not use PROC IMPORT. With a csv file, write the data step yourself in the first place.&lt;/P&gt;</description>
    <pubDate>Sat, 26 Dec 2020 06:49:52 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-12-26T06:49:52Z</dc:date>
    <item>
      <title>Retaining label from csv import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-label-from-csv-import/m-p/708243#M217618</link>
      <description>&lt;P&gt;I wanted to retain the label on sas dataset after importing a file from csv file. Can someone please help me with the code. I wrote the following code and the label becoming as blanl on sas file. thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC IMPORT DATAFILE="C:\test.csv"
OUT=want
DBMS=csv REPLACE;
GETNAMES=Yes;
GUESSINGROWS=14600;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Dec 2020 04:26:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-label-from-csv-import/m-p/708243#M217618</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2020-12-26T04:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining label from csv import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-label-from-csv-import/m-p/708245#M217620</link>
      <description>&lt;P&gt;Take the data step from the log and adapt it as needed.&lt;/P&gt;
&lt;P&gt;Even better, do not use PROC IMPORT. With a csv file, write the data step yourself in the first place.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Dec 2020 06:49:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-label-from-csv-import/m-p/708245#M217620</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-26T06:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining label from csv import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-label-from-csv-import/m-p/708268#M217646</link>
      <description>&lt;P&gt;If you want to add a member label to your dataset use the LABEL= dataset option when creating the dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;out=want(label='Data imported from C:\test.csv')&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Dec 2020 15:28:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-label-from-csv-import/m-p/708268#M217646</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-26T15:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining label from csv import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-label-from-csv-import/m-p/708274#M217648</link>
      <description>&lt;P&gt;I think you are asking how to attach labels to the variables created by PROC IMPORT?&amp;nbsp; The proc will not attach labels to variables it creates from reading text files.&amp;nbsp; There is no need to attach labels to every variable because any procedure that prints labels will just print the variable name instead if there is no explicit label attached.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you would like to know how to attach the column headers from the CSV as labels on the variables that PROC IMPORT created for those columns?&amp;nbsp; &amp;nbsp; If so then just re-read the header row and use it to generate LABEL statement(s).&amp;nbsp; First you need to know what names PROC IMPORT generated for the variables.&amp;nbsp; One easy way is to use PROC TRANSPOSE with OBS=0 dataset option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename csv 'c:\test.csv';
proc import datafile=csv dbms=csv out=want replace ;
run;

proc transpose data=want(obs=0) out=names;
  var _all_;
run;

filename labels temp;
data names ;
  length _name_ $51 _label_ header $256 ;
  set names end=eof;
  infile csv dsd obs=1 truncover;
  input header @@ ;
  _label_=coalescec(header,_name_);
  _name_=nliteral(_name_);
  file labels ;
  if _n_=1 then put 'label' ;
  put @3 _name_ '=' _label_ :$quote.  ;
  if eof then put ';' ;
run;

proc datasets lib=work nolist;
  modify want;
%include labels / source2;
  run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Dec 2020 17:49:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-label-from-csv-import/m-p/708274#M217648</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-26T17:49:57Z</dc:date>
    </item>
  </channel>
</rss>

