<?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: Covert the first observation values to variabale names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846938#M334830</link>
    <description>&lt;P&gt;The code has been updated to account for the missing NOBS= option and other issues.&lt;/P&gt;
&lt;P&gt;But if you still ahve the original XLSX file you don't need it.&amp;nbsp; You can tell SAS to skip the first line when importing the file.&amp;nbsp; That will also allow SAS to discover any numeric variables that might be in the there since it no longer will treat the column headers as data.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Nov 2022 22:09:53 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-11-29T22:09:53Z</dc:date>
    <item>
      <title>Covert the first observation values to variabale names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846924#M334820</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a sas dataset that has values like below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RAVI2000_0-1669756879903.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77829iF17064D6FAE86E42/image-dimensions/640x39?v=v2" width="640" height="39" role="button" title="RAVI2000_0-1669756879903.png" alt="RAVI2000_0-1669756879903.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The variable name "LSIDEM01_Listing_of_Subject_Dem" is very big. I want the observation 1 values to be variable names for all the B, C, D, E, F, G, H....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 21:23:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846924#M334820</guid>
      <dc:creator>RAVI2000</dc:creator>
      <dc:date>2022-11-29T21:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Covert the first observation values to variabale names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846926#M334821</link>
      <description>&lt;P&gt;How was the dataset you have created?&amp;nbsp; With names like B,C,D,... it looks like you imported a spreadsheet.&amp;nbsp; So why not take a step back and create the dataset with valid names to begin with?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 21:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846926#M334821</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-29T21:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: Covert the first observation values to variabale names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846930#M334823</link>
      <description>&lt;P&gt;Transpose the first row.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=HAVE(obs=1) out=names name=oldname;
  var _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now convert the gibberish into something that could be used as a variable name, you can use the original gibberish as the label.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data names;
  length varnum 8 oldname name $32 label $256 ;
  set names;
  varnum+1;
  label=col1;
* Replace adjacent non-valid characters with single underscore ;
  name=translate(trim(prxchange('s/([^a-zA-Z0-9]+)/ /',-1,col1)),' _','_ ');
  name=prxchange('s/(^[0-9])/_$1/',1,name);  
  drop col1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now generate code to rename the variables and attach the labels.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  file code;
  put 'rename' ;
  do p=1 to nobs;
    set names point=p nobs=nobs;
    if upcase(name) ne upcase(oldname) then 
      put oldname '=' name 
    ;
  end;
  put ';' ;
  do p=1 to nobs;
    set names point=p;
    if label ne name then do;
      label=quote(trim(label),"'");
      put 'label ' oldname '=' label ';' ;
    end;
  end;
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use the generated RENAME and LABEL statements in either a new data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have(firstobs=2);
%include code / source2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or as part of a PROC DATASETS step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc dataset nolist lib=work;
modify have ;
%include code / source2;
run;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 21:50:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846930#M334823</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-29T21:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Covert the first observation values to variabale names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846931#M334824</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;  It was imported from excel, I didn't create it. It comes from a different team and I cannot edit it. I can only import and then do more modifications.</description>
      <pubDate>Tue, 29 Nov 2022 21:42:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846931#M334824</guid>
      <dc:creator>RAVI2000</dc:creator>
      <dc:date>2022-11-29T21:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Covert the first observation values to variabale names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846932#M334825</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294544"&gt;@RAVI2000&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; It was imported from excel, I didn't create it. It comes from a different team and I cannot edit it. I can only import and then do more modifications.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your first and last sentences contradict each other.&amp;nbsp; Assuming the last one is correct and it was you that created the dataset by importing an Excel file then just change how you imported it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import file='somefile.xlsx' dbms=xlsx out=want replace;
  range='$A2:';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 21:54:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846932#M334825</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-29T21:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: Covert the first observation values to variabale names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846934#M334826</link>
      <description>&lt;P&gt;I have tried your code, and I work on cloud studio.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RAVI2000_0-1669759439509.png" style="width: 725px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77833iAA2918AFC37371B9/image-dimensions/725x336?v=v2" width="725" height="336" role="button" title="RAVI2000_0-1669759439509.png" alt="RAVI2000_0-1669759439509.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The "filename" statement is not reading the correct temp path.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 22:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846934#M334826</guid>
      <dc:creator>RAVI2000</dc:creator>
      <dc:date>2022-11-29T22:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: Covert the first observation values to variabale names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846937#M334829</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294544"&gt;@RAVI2000&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; It was imported from excel, I didn't create it. It comes from a different team and I cannot edit it. I can only import and then do more modifications.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You could ... politely ... ask them to re-do it such that the problem is fixed. To me this is the optimal solution. You're lucky &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; has figured out how to fix this in SAS, I would not have even tried.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 22:08:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846937#M334829</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-29T22:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: Covert the first observation values to variabale names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846938#M334830</link>
      <description>&lt;P&gt;The code has been updated to account for the missing NOBS= option and other issues.&lt;/P&gt;
&lt;P&gt;But if you still ahve the original XLSX file you don't need it.&amp;nbsp; You can tell SAS to skip the first line when importing the file.&amp;nbsp; That will also allow SAS to discover any numeric variables that might be in the there since it no longer will treat the column headers as data.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 22:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846938#M334830</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-29T22:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: Covert the first observation values to variabale names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846939#M334831</link>
      <description>Yes, going forward we have raised a request. That is really not a good data to work on with.</description>
      <pubDate>Tue, 29 Nov 2022 22:10:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846939#M334831</guid>
      <dc:creator>RAVI2000</dc:creator>
      <dc:date>2022-11-29T22:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: Covert the first observation values to variabale names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846940#M334832</link>
      <description>What option in proc import do I specify for it? I have tried it with range and datarow options. I didn't get exact row of the data that I am looking for. This excel has the variables values in the first observation. But other sheet have the values in 4th , 5th observations.</description>
      <pubDate>Tue, 29 Nov 2022 22:15:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846940#M334832</guid>
      <dc:creator>RAVI2000</dc:creator>
      <dc:date>2022-11-29T22:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Covert the first observation values to variabale names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846942#M334834</link>
      <description>&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile="mydatafile.xlsx" out=abc dbms=excel replace;
    getnames=yes;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Nov 2022 22:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846942#M334834</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-29T22:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: Covert the first observation values to variabale names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846944#M334836</link>
      <description>Thank you very much &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; It really helped me alot!</description>
      <pubDate>Tue, 29 Nov 2022 22:33:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846944#M334836</guid>
      <dc:creator>RAVI2000</dc:creator>
      <dc:date>2022-11-29T22:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: Covert the first observation values to variabale names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846951#M334842</link>
      <description>&lt;P&gt;Use the RANGE option to specify the upper left corner and PROC IMPORT will import that.&lt;/P&gt;
&lt;P&gt;So to skip the first row then start in A2.&amp;nbsp; To skip 4 lines start in A5.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import file='c:\downloads\test_range.xlsx' dbms=xlsx out=want replace;
  range='$A2:' ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the file also includes junk below or to the right of the table then specify the full range.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import file='c:\downloads\test_range.xlsx' dbms=xlsx out=want replace;
  range='$A2:E18' ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 01:31:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-the-first-observation-values-to-variabale-names/m-p/846951#M334842</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-30T01:31:47Z</dc:date>
    </item>
  </channel>
</rss>

