<?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: From imported CSV, keep variable names and apply labels from CSV cell in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/From-imported-CSV-keep-variable-names-and-apply-labels-from-CSV/m-p/863455#M341075</link>
    <description>&lt;P&gt;Tom, thank you for taking the time out of your day to help me out. I truly appreciate the detail and examples you shared; I was able to follow along and make it work on my end. Thank you again!&lt;/P&gt;</description>
    <pubDate>Fri, 10 Mar 2023 14:54:25 GMT</pubDate>
    <dc:creator>cedpme</dc:creator>
    <dc:date>2023-03-10T14:54:25Z</dc:date>
    <item>
      <title>From imported CSV, keep variable names and apply labels from CSV cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/From-imported-CSV-keep-variable-names-and-apply-labels-from-CSV/m-p/863305#M341029</link>
      <description>&lt;P&gt;Hello all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS EG 8.3.&lt;/P&gt;&lt;P&gt;Scenario: assuming you have a table and you generate the &lt;STRONG&gt;proc contents&lt;/STRONG&gt; from this table, you would get something like this (I created a dummy table called "TESTING_FIELDNAMES_LABELNAMES1" then exported to Microsoft Excel, keeping pertinent fields that I need):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC CONTENTS Export:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;I highlighted the field "LABEL", this where I need your help&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cedpme_1-1678395549930.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81280i21D62F61FD66A111/image-size/large?v=v2&amp;amp;px=999" role="button" title="cedpme_1-1678395549930.png" alt="cedpme_1-1678395549930.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a mockup of the labels I would modify in Excel, hoping I can import it later to modify my table with updated labels:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cedpme_4-1678396397011.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81284i33D9C274D2931DA5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cedpme_4-1678396397011.png" alt="cedpme_4-1678396397011.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I know I can use the &lt;STRONG&gt;LABEL&lt;/STRONG&gt; function in a &lt;STRONG&gt;SAS Datastep&lt;/STRONG&gt; to add my labels, as follows:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cedpme_5-1678396569883.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81285i02A7869D19A0D1F7/image-size/large?v=v2&amp;amp;px=999" role="button" title="cedpme_5-1678396569883.png" alt="cedpme_5-1678396569883.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which will update my labels as follows:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cedpme_6-1678396686371.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81287i87296BD83CEEA414/image-size/large?v=v2&amp;amp;px=999" role="button" title="cedpme_6-1678396686371.png" alt="cedpme_6-1678396686371.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Reason: I have built several data marts that are sources of truth that many departments use. The issue I have is that I constantly get question asking for field sourcing or how a calculated field is created. My hope is that I can maintain an the extracted PROC CONTENTS workbook for each data asset, update the labels as necessary, then import the updated workbook back into the project giving me sudo "dynamic labels" that are easy to maintain by my team.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 21:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/From-imported-CSV-keep-variable-names-and-apply-labels-from-CSV/m-p/863305#M341029</guid>
      <dc:creator>cedpme</dc:creator>
      <dc:date>2023-03-09T21:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: From imported CSV, keep variable names and apply labels from CSV cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/From-imported-CSV-keep-variable-names-and-apply-labels-from-CSV/m-p/863307#M341031</link>
      <description>&lt;P&gt;Create a dataset with library, memname, variable name and label text (use a DATA step with DATALINES), from which you can create code for PROC DATASETS with CALL EXECUTE.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 21:37:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/From-imported-CSV-keep-variable-names-and-apply-labels-from-CSV/m-p/863307#M341031</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-09T21:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: From imported CSV, keep variable names and apply labels from CSV cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/From-imported-CSV-keep-variable-names-and-apply-labels-from-CSV/m-p/863318#M341038</link>
      <description>&lt;P&gt;There is no function named LABEL. What you showed is the LABEL statement.&lt;/P&gt;
&lt;P&gt;You will need to use code generation to convert your data into a label statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the set of variables is small you can just put the code into a single macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select catx('=',nliteral(name),quote(trim(label))
  into :labels separated by ' '
  from HAVE 
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which you can then use as part of a LABEL statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LABEL &amp;amp;labels ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But remember that a macro variable can only hold 64K bytes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you have too much to put into one macro variable just write the code to a file instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  set have end=eof;
  file code ;
  if _n_=1 then put 'label' ;
  nname=nliteral(name);
  put nname '=' label :$quote. ;
  if eof then put ';' ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you are running a data step to create the dataset then just add this label statement to that step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data pretty ;
  set ugly ;
  %include code / source2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or if you already have the dataset and you want to change the labels then use PROC DATASETS instead.&amp;nbsp; So to add the labels to MYLIB.PRETTY use code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets lib=MYLIB nolist;
  modify pretty ;
%include code / source2;
  run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Mar 2023 23:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/From-imported-CSV-keep-variable-names-and-apply-labels-from-CSV/m-p/863318#M341038</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-09T23:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: From imported CSV, keep variable names and apply labels from CSV cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/From-imported-CSV-keep-variable-names-and-apply-labels-from-CSV/m-p/863455#M341075</link>
      <description>&lt;P&gt;Tom, thank you for taking the time out of your day to help me out. I truly appreciate the detail and examples you shared; I was able to follow along and make it work on my end. Thank you again!&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 14:54:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/From-imported-CSV-keep-variable-names-and-apply-labels-from-CSV/m-p/863455#M341075</guid>
      <dc:creator>cedpme</dc:creator>
      <dc:date>2023-03-10T14:54:25Z</dc:date>
    </item>
    <item>
      <title>Re: From imported CSV, keep variable names and apply labels from CSV cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/From-imported-CSV-keep-variable-names-and-apply-labels-from-CSV/m-p/863458#M341077</link>
      <description>Kurt, thank you for your reply; unfortunately I am not as familiar with SAS as you are. I understood what you shared, but without examples or code to test on my end, I wasn't able to get the results I needed. I am sure others will be able to grasp the concepts you share and quickly get a solution; nonetheless, thank you for helping me out.</description>
      <pubDate>Fri, 10 Mar 2023 14:58:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/From-imported-CSV-keep-variable-names-and-apply-labels-from-CSV/m-p/863458#M341077</guid>
      <dc:creator>cedpme</dc:creator>
      <dc:date>2023-03-10T14:58:07Z</dc:date>
    </item>
  </channel>
</rss>

