<?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: var names change after import in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471020#M120602</link>
    <description>&lt;P&gt;Doesn't that just ignore the initial problem, and then increase the future coding even more - i.e. having to refer to '01/12/18'n each time, rather than a proper SAS name?&amp;nbsp; Just thinking, no lists or shortcuts then, possible unmatched quotes, impossible to read code etc.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Jun 2018 10:14:27 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-06-18T10:14:27Z</dc:date>
    <item>
      <title>var names change after import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471009#M120596</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I am importing a CSV file, it is changing some of the variables name from say e.g 01/01/00 to var1. Please note that my variables are all dates. Although some of the variables names are imported as&amp;nbsp;_01/01/00 which is fine but the rest as var xyz. Any suggestions on how to handle this issue?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 09:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471009#M120596</guid>
      <dc:creator>Amalik</dc:creator>
      <dc:date>2018-06-18T09:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: var names change after import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471011#M120597</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please share the code you are using for importing the CSV and a representative sample of the data, including the first record.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 09:41:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471011#M120597</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2018-06-18T09:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: var names change after import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471014#M120598</link>
      <description>&lt;P&gt;Please find below,&lt;/P&gt;&lt;PRE&gt;proc import datafile="C:\Users\amalik\Desktop\dailydata\HAVE.csv"
        out=have1
        dbms=csv
        replace;
		GETNAMES=YES;
		run;&lt;BR /&gt;;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21242i79D7C2064A4D97D2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Untitled.png" alt="Untitled.png" /&gt;&lt;/span&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Jun 2018 09:48:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471014#M120598</guid>
      <dc:creator>Amalik</dc:creator>
      <dc:date>2018-06-18T09:48:31Z</dc:date>
    </item>
    <item>
      <title>Re: var names change after import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471015#M120599</link>
      <description>&lt;P&gt;How are you importing the csv file?&amp;nbsp; I guess you are using proc import yes.&amp;nbsp; That is not the best idea as proc import is a&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;guessing&lt;/STRONG&gt;&lt;/U&gt; procedure.&amp;nbsp; Now 01/01/00 is not a valid variable name hence why sas adds a underscore to the name.&amp;nbsp; However, it is likely not guessing all your variables correctly.&amp;nbsp; To handle this properly (well, I will get onto "properly" shortly) take the code that is generated - you will find it in the log after running the proc import, then put this in a code window and change the names to what they should be.&amp;nbsp; Then run that datastep import.&amp;nbsp; Datastep import allows full control over the file coming in, how the data is to be read, and what the output should look like - this is what proc import guesses at, but as you know your data better, you should code this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, lets get onto to "properly" importing the data.&amp;nbsp; Having variable names like 01/01/00 is a really bad idea for a number of reasons.&amp;nbsp; Firstly it is not easily readable by software - which is your issue here.&amp;nbsp; Secondly it is very hard to write good code which can process a non-fixed datastructure (i.e. more dates could be added, or removed etc.).&amp;nbsp; It is also not good to put partial data anywhere, 01/01/00, could mean any number of things - dates are an abstract concept.&amp;nbsp; Finally, data as columns will really cause you headaches.&amp;nbsp; How will you program with these possibly hundreds or thousands of columns?&amp;nbsp; Yes, you will write endless macro code to try to work out variable names and loop over these, wasting your time, and storage/processing time.&amp;nbsp; A simple change to the data from:&lt;/P&gt;
&lt;P&gt;... 01/0/1/00&amp;nbsp; 02/0/1/00&amp;nbsp; 03/01/00...&lt;/P&gt;
&lt;P&gt;... a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c...&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To:&lt;/P&gt;
&lt;P&gt;...&amp;nbsp; &amp;nbsp;Date_var&amp;nbsp; &amp;nbsp; result&lt;/P&gt;
&lt;P&gt;...&amp;nbsp; &amp;nbsp;01Jan2000 a&lt;/P&gt;
&lt;P&gt;...&amp;nbsp; &amp;nbsp;02Jan2000 b&lt;/P&gt;
&lt;P&gt;...&amp;nbsp; &amp;nbsp;03Jan2000 c&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;Will result in&amp;nbsp; a far simpler import, far simpler programming to work with it, and most likely will be a smaller file to work with.&lt;/P&gt;
&lt;P&gt;That is my suggestion on "&lt;SPAN&gt;how to handle this issue".&amp;nbsp; In fact it is my suggestion whenever talking about data from Excel.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 09:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471015#M120599</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-18T09:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: var names change after import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471018#M120601</link>
      <description>&lt;P&gt;add system option before running PROC IMPORT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options validvarname=any ;&lt;/P&gt;
&lt;P&gt;proc import ..........&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and refer to these special variable name via '01/12/2018'n&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 10:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471018#M120601</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-06-18T10:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: var names change after import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471020#M120602</link>
      <description>&lt;P&gt;Doesn't that just ignore the initial problem, and then increase the future coding even more - i.e. having to refer to '01/12/18'n each time, rather than a proper SAS name?&amp;nbsp; Just thinking, no lists or shortcuts then, possible unmatched quotes, impossible to read code etc.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 10:14:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471020#M120602</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-18T10:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: var names change after import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471025#M120604</link>
      <description>&lt;P&gt;Yeah. You are right . But you are standing on English language side .&lt;/P&gt;
&lt;P&gt;If your mother language is not English, like me (from China), make a variable name as a Chinese name that would make code more readable due to most Chinese can barely read English .&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 10:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471025#M120604</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-06-18T10:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: var names change after import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471032#M120607</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/114858"&gt;@Amalik&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I am importing a CSV file, it is changing some of the variables name from say e.g 01/01/00 to var1. Please note that my variables are all dates. Although some of the variables names are imported as&amp;nbsp;_01/01/00 which is fine but the rest as var xyz. Any suggestions on how to handle this issue?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's because 01/01/00 is not a a valid SAS name. Read the SAS documentation about that (google "SAS valid names").&lt;/P&gt;
&lt;P&gt;Keeping data (dates) in structure (variable names) is to be avoided. After import, transpose your dataset and use the _name_ field for converting into valid SAS dates:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input '_11/27/09'n '_11/28/09'n '_11/29/09'n;
cards;
-2.17 0 0
-2.26 0 0
-2.64 0 0
;
run;

proc transpose data=have out=int;
var _numeric_;
run;

data want;
format date yymmddd10.;
set int;
date = input(substr(_name_,2),mmddyy9.);
drop _name_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Add by-group processing to the transpose step to create separate rows instead of COL1-Coln.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 11:11:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471032#M120607</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-18T11:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: var names change after import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471101#M120632</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/114858"&gt;@Amalik&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Please find below,&lt;/P&gt;
&lt;PRE&gt;proc import datafile="C:\Users\amalik\Desktop\dailydata\HAVE.csv"
        out=have1
        dbms=csv
        replace;
		GETNAMES=YES;
		run;&lt;BR /&gt;;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21242i79D7C2064A4D97D2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Untitled.png" alt="Untitled.png" /&gt;&lt;/span&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One column per date is likely going to present other difficulties later in processing this data.&lt;/P&gt;
&lt;P&gt;Also getting variable names&amp;nbsp;like VAR3634 indicates that you have thousands of variables. While SAS will handle such it may well be worth considering what kind of code you will have to write to handle thousands of variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 14:29:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/471101#M120632</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-06-18T14:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: var names change after import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/935073#M367648</link>
      <description>&lt;P&gt;Thanks, this also solves how to automatically process dynamic data sets where the owners may add and drop variables. Added code to automatically clean up into a usable variable name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options validvarname=any;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc import datafile = 'Participants.xlsx'&lt;BR /&gt;out = participants&lt;BR /&gt;dbms = xlsx&lt;BR /&gt;replace;&lt;BR /&gt;getnames=YES;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc contents data=participants out=contents(keep=name) noprint; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new_names;&lt;BR /&gt;set contents;&lt;BR /&gt;length name_new $32.;&lt;BR /&gt;lead_val=rank(substr(strip(name),1,1));&lt;BR /&gt;if ((lead_val&amp;gt;=65 &amp;amp; lead_val&amp;lt;=90) | (lead_val&amp;gt;=97 &amp;amp; lead_val&amp;lt;=122)) then lead_ok=1;&lt;BR /&gt;name_new=prxchange("s/[^a-zA-Z0-9]/_/", -1, strip(name));&lt;BR /&gt;if (missing(lead_ok)) then name_new="_"||name_new;&lt;BR /&gt;name_new=tranwrd(name_new,"___","_");&lt;BR /&gt;name_new=tranwrd(name_new,"__","_");&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select nliteral(name)||"="||name_new&lt;BR /&gt;into :renam_list separated by ' '&lt;BR /&gt;from new_names;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data participants_new;&lt;BR /&gt;set participants;&lt;BR /&gt;rename &amp;amp;renam_list;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2024 23:43:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/var-names-change-after-import/m-p/935073#M367648</guid>
      <dc:creator>little_irishman</dc:creator>
      <dc:date>2024-07-08T23:43:44Z</dc:date>
    </item>
  </channel>
</rss>

