<?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: Creating sas datafile where variables are named in another file? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-sas-datafile-where-variables-are-named-in-another-file/m-p/433959#M107664</link>
    <description>&lt;P&gt;First step:&amp;nbsp; convert your csv files to SAS data sets.&amp;nbsp; Then we can begin the conversation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second step:&amp;nbsp; consider whether you really want to do this.&amp;nbsp; If you have a variable named age, you can refer to it as age.&amp;nbsp; If you have a variable named Age at first diagnosis, your programs will need to refer to it as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'Age at first diagnosis'n&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The program gets a bit clumsy but it can be done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Third step depends on your decision in step 2.&amp;nbsp; Do you really want to change the variable names, or do you just want to assign labels to the variables?&amp;nbsp; In most cases, you will have a choice of whether a report should print the variable name vs. the variable label.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fourth step:&amp;nbsp; Use the second file to write to a temporary file, containing the code that you need to implement.&amp;nbsp; For&amp;nbsp; example, the second file might be created to contain:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;label age = 'Age at first diagnosis';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or it might be designed to contain:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;rename age = 'Age at first diagnosis'n;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whichever your choice, the second file becomes the input to a DATA step, and that DATA step writes out either a set of LABEL statements or a set of RENAME statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fifth step:&amp;nbsp; apply that file to the first data set.&amp;nbsp; The general idea:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set first_dataset;&lt;/P&gt;
&lt;P&gt;%include "file holding either RENAME or LABEL statements";&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Sun, 04 Feb 2018 13:13:58 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-02-04T13:13:58Z</dc:date>
    <item>
      <title>Creating sas datafile where variables are named in another file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-sas-datafile-where-variables-are-named-in-another-file/m-p/433948#M107659</link>
      <description>&lt;P&gt;Hi there. I am on SAS 9.4. I have two csv files, one containing data and another containing two columns, one for the variables of the first file and the second for what I am supposed to rename them to, something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;file 1 - base age yr&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;some data..&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;some data..&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;some data..&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;file 2 -&amp;nbsp;&lt;/P&gt;&lt;P&gt;var_dict&amp;nbsp; var2&lt;/P&gt;&lt;P&gt;base&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Baseline&amp;nbsp;&lt;/P&gt;&lt;P&gt;age&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Age at first diagnosis&lt;/P&gt;&lt;P&gt;yr&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Duration in years&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How am I supposed to get around to renaming file1's variables to file2's? I was thinking PROC TRANSPOSE and an if loop but I can't quite seem to get my head around the logic of it? Any help is appreciated. My code so far is just importing both csv files I'm stuck from there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2018 11:17:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-sas-datafile-where-variables-are-named-in-another-file/m-p/433948#M107659</guid>
      <dc:creator>amaple</dc:creator>
      <dc:date>2018-02-04T11:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: Creating sas datafile where variables are named in another file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-sas-datafile-where-variables-are-named-in-another-file/m-p/433959#M107664</link>
      <description>&lt;P&gt;First step:&amp;nbsp; convert your csv files to SAS data sets.&amp;nbsp; Then we can begin the conversation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second step:&amp;nbsp; consider whether you really want to do this.&amp;nbsp; If you have a variable named age, you can refer to it as age.&amp;nbsp; If you have a variable named Age at first diagnosis, your programs will need to refer to it as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'Age at first diagnosis'n&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The program gets a bit clumsy but it can be done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Third step depends on your decision in step 2.&amp;nbsp; Do you really want to change the variable names, or do you just want to assign labels to the variables?&amp;nbsp; In most cases, you will have a choice of whether a report should print the variable name vs. the variable label.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fourth step:&amp;nbsp; Use the second file to write to a temporary file, containing the code that you need to implement.&amp;nbsp; For&amp;nbsp; example, the second file might be created to contain:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;label age = 'Age at first diagnosis';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or it might be designed to contain:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;rename age = 'Age at first diagnosis'n;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whichever your choice, the second file becomes the input to a DATA step, and that DATA step writes out either a set of LABEL statements or a set of RENAME statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fifth step:&amp;nbsp; apply that file to the first data set.&amp;nbsp; The general idea:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set first_dataset;&lt;/P&gt;
&lt;P&gt;%include "file holding either RENAME or LABEL statements";&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2018 13:13:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-sas-datafile-where-variables-are-named-in-another-file/m-p/433959#M107664</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-04T13:13:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating sas datafile where variables are named in another file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-sas-datafile-where-variables-are-named-in-another-file/m-p/434002#M107674</link>
      <description>&lt;P&gt;Those don't look like variable names, they look like labels.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example of how you can do that, with a fully worked example code that you can run. This is a dynamic approach, but if the macro variables were to become larger than 65K characters it wouldn't work. So as long as your variable lists is relatively short you should be fine.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/f18931085f6a0009185c" target="_blank"&gt;https://gist.github.com/statgeek/f18931085f6a0009185c&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/191307"&gt;@amaple&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi there. I am on SAS 9.4. I have two csv files, one containing data and another containing two columns, one for the variables of the first file and the second for what I am supposed to rename them to, something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;file 1 - base age yr&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;some data..&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;some data..&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;some data..&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;file 2 -&amp;nbsp;&lt;/P&gt;
&lt;P&gt;var_dict&amp;nbsp; var2&lt;/P&gt;
&lt;P&gt;base&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Baseline&amp;nbsp;&lt;/P&gt;
&lt;P&gt;age&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Age at first diagnosis&lt;/P&gt;
&lt;P&gt;yr&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Duration in years&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How am I supposed to get around to renaming file1's variables to file2's? I was thinking PROC TRANSPOSE and an if loop but I can't quite seem to get my head around the logic of it? Any help is appreciated. My code so far is just importing both csv files I'm stuck from there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2018 20:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-sas-datafile-where-variables-are-named-in-another-file/m-p/434002#M107674</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-04T20:03:58Z</dc:date>
    </item>
  </channel>
</rss>

