<?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: Labelling my data with labels corrected in a CSV file. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775075#M246380</link>
    <description>&lt;P&gt;Thank you so much for your reply&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;! I seems like it could work!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However I get an error. It doesn't seem to accept the:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=""&gt;&lt;CODE&gt;put name '=' label;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 73-322: Expecting an =.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;</description>
    <pubDate>Tue, 19 Oct 2021 10:53:58 GMT</pubDate>
    <dc:creator>Ninna1</dc:creator>
    <dc:date>2021-10-19T10:53:58Z</dc:date>
    <item>
      <title>Labelling my data with labels corrected in a CSV file.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775060#M246376</link>
      <description>&lt;P&gt;Hello fellow programmers!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to figure this out myself, but I guess I need help:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a large amount of survey data, and all the answer-variables have labels that are the survey questions - naturally. Not all of them are correct from the beginning, so I put them in a csv file and send them to be reviewed. Usually there is not anything to correct, so I just leave it there. If there is a single mistake i just correct it manually in my programming.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But now, there is many variables that needs new labels, so I would like to be able to do it more clever than copy/paste.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The csv file is just two collums, one with the variable names and one with the labels.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas or tips?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking forward to hearing from you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 08:54:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775060#M246376</guid>
      <dc:creator>Ninna1</dc:creator>
      <dc:date>2021-10-19T08:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: Labelling my data with labels corrected in a CSV file.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775068#M246377</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* 
Post_title:
	Labelling my data with labels corrected in a CSV file.
Link to post: 
	https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775060
Important post details:	
	The csv file is just two collums, one with the variable names and one with the labels.

*/

*if you are using SAS OnDemand for Academics (ODA) 
    change your-userid-on-oda for your userid
 if you are using another option then change
    /home/your-userid-on-oda/ for a path/folder 
    you can use;
%let mypath = /home/your-userid-on-oda/;

data work.dataset_with_labels;
   variable_name = "abc";
   variable_label = "label-for-abc";
run;

proc export data = work.dataset_with_labels
            outfile = "&amp;amp;mypath.dataset_with_labels.csv"
            replace;
run;

proc import datafile = "&amp;amp;mypath.dataset_with_labels.csv"
            out = work.imported_dataset_with_labels
            replace;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does this make sense for you?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards, Jos&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 09:34:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775068#M246377</guid>
      <dc:creator>JosvanderVelden</dc:creator>
      <dc:date>2021-10-19T09:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: Labelling my data with labels corrected in a CSV file.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775069#M246378</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349190"&gt;@Ninna1&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, you have&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;a dataset with variables containing the answers to survey questions and some of these variables have wrong labels&lt;/LI&gt;
&lt;LI&gt;a CSV file with pairs of variable names from the above dataset and correct labels.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Let me create sample data for demonstration:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
array s[*] $ Q1a Q1b Q2 Q3;
label Q1a='First question, part a)'
      Q1b='Wrong label'
      Q2 ='Second question'
      Q3 ='Again, incorrect label';
input s[*];
cards;
Yes No Maybe Never
; 

filename namlab 'C:\Temp\correct_labels.csv';

data _null_;
file namlab;
put 'Q1b,"First question, part b)"' /
    'Q3,Third question';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To correct the labels in dataset HAVE you can create PROC DATASETS code (in a temporary file) using the information from the CSV file and then run it per %INCLUDE statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename labels temp;

data _null_;
file labels;
infile namlab dlm=',' dsd end=last;
input name :$32. label :$256.;
if _n_=1 then put 'proc datasets lib=work nolist;' /
                  'modify have;' /
                  'label ';
put name '=' label;
if last then put '; quit;';
run;

%inc labels;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 09:50:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775069#M246378</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-10-19T09:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: Labelling my data with labels corrected in a CSV file.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775075#M246380</link>
      <description>&lt;P&gt;Thank you so much for your reply&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;! I seems like it could work!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However I get an error. It doesn't seem to accept the:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=""&gt;&lt;CODE&gt;put name '=' label;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 73-322: Expecting an =.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 10:53:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775075#M246380</guid>
      <dc:creator>Ninna1</dc:creator>
      <dc:date>2021-10-19T10:53:58Z</dc:date>
    </item>
    <item>
      <title>Re: Labelling my data with labels corrected in a CSV file.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775076#M246381</link>
      <description>Yes it makes perfect sense but i can't really see how this brings me any closer to replacing be wrong labels with the correct ones?</description>
      <pubDate>Tue, 19 Oct 2021 11:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775076#M246381</guid>
      <dc:creator>Ninna1</dc:creator>
      <dc:date>2021-10-19T11:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: Labelling my data with labels corrected in a CSV file.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775077#M246382</link>
      <description>&lt;P&gt;We need to see an example of your csv file with names and labels to provide tested code that works with it.&lt;/P&gt;
&lt;P&gt;Copy/paste this text into a box opened with this button:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54552i914D97BE1B0F21E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 11:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775077#M246382</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-19T11:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: Labelling my data with labels corrected in a CSV file.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775081#M246383</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349190"&gt;@Ninna1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you so much for your reply&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;! I seems like it could work!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However I get an error. It doesn't seem to accept the:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=""&gt;&lt;CODE&gt;put name '=' label;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get this :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR 73-322: Expecting an =.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I suspect that you are using non-standard variable names, e.g. containing blanks such as &lt;FONT face="courier new,courier"&gt;Question 1a&lt;/FONT&gt;. In this case you will have&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in effect and you need to modify the &lt;FONT face="courier new,courier"&gt;data _null_&lt;/FONT&gt; step as follows in order to handle &lt;EM&gt;name literals&lt;/EM&gt;:&lt;/P&gt;
&lt;PRE&gt;data _null_;
file labels;
infile namlab dlm=',' dsd end=last;
input name :$32. label :$256.;
&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;length nl $35;&lt;/STRONG&gt;&lt;/FONT&gt; /* &lt;EM&gt;safer: $51&lt;/EM&gt; */
&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;nl=nliteral(name);&lt;/STRONG&gt;&lt;/FONT&gt;
if _n_=1 then put 'proc datasets lib=work nolist;' /
                  'modify have;' /
                  'label ';
put &lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;nl&lt;/STRONG&gt;&lt;/FONT&gt; '=' label;
if last then put '; quit;';
run;&lt;/PRE&gt;
&lt;P&gt;Edit: Here is a complete example using name literals:&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;

data have;
array s[*] $ 'First Q a'n 'First Q b'n 'Second Q'n '3rd Q.'n; /* name literals -- not recommended */
label 'First Q a'n = 'First question, part a)'
      'First Q b'n = 'Wrong label'
      'Second Q'n  = 'Second question'
      '3rd Q.'n    = 'Again, incorrect label';
input s[*];
cards;
Yes No Maybe Never
; 

filename namlab 'C:\Temp\correct_labels.csv';

data _null_;
file namlab;
put 'First Q b,"First question, part b)"' /
    '3rd Q.,Third question';
run;

filename labels temp;

data _null_;
file labels;
infile namlab dlm=',' dsd end=last;
input name :$32. label :$256.;
length nl $35;
nl=nliteral(name);
if _n_=1 then put 'proc datasets lib=work nolist;' /
                  'modify have;' /
                  'label ';
put nl '=' label;
if last then put '; quit;';
run;

%inc labels;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 14:17:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775081#M246383</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-10-19T14:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: Labelling my data with labels corrected in a CSV file.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775099#M246390</link>
      <description>Thank you very much for your effort @FreelanceReinhard. It almost works.&lt;BR /&gt;&lt;BR /&gt;I get a ; instead of the =&lt;BR /&gt;&lt;BR /&gt;I have no idea why. However, I have allready spent too much time on this today and I have a deadline. So I will have to work on it some other time.&lt;BR /&gt;&lt;BR /&gt;Thank you all.</description>
      <pubDate>Tue, 19 Oct 2021 12:52:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775099#M246390</guid>
      <dc:creator>Ninna1</dc:creator>
      <dc:date>2021-10-19T12:52:26Z</dc:date>
    </item>
    <item>
      <title>Re: Labelling my data with labels corrected in a CSV file.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775111#M246397</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349190"&gt;@Ninna1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I get a ; instead of the =&lt;BR /&gt;&lt;BR /&gt;I have no idea why. However, I have allready spent too much time on this today and I have a deadline. So I will have to work on it some other time.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No problem. When you get back to this, please post the complete log of the step that doesn't work into a code box opened with the &amp;lt;/&amp;gt; ("Insert Code") button.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 13:17:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775111#M246397</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-10-19T13:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: Labelling my data with labels corrected in a CSV file.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775114#M246399</link>
      <description>&lt;P&gt;Make sure to define&amp;nbsp;nl long enough for any possible nliteral.&amp;nbsp; You need 32 characters for the actual name plus three for the quotes and N suffix.&amp;nbsp; But you also need up to 16 more for doubling up any included quotes.&amp;nbsp; So use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length nl $51;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Oct 2021 13:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775114#M246399</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-10-19T13:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: Labelling my data with labels corrected in a CSV file.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775136#M246404</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;, good point. Indeed, the "worst case" regarding variable names that I had envisioned was not bad enough.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 14:06:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Labelling-my-data-with-labels-corrected-in-a-CSV-file/m-p/775136#M246404</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-10-19T14:06:33Z</dc:date>
    </item>
  </channel>
</rss>

