<?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: how to import data specs (excel) onto program in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-data-specs-excel-onto-program/m-p/896420#M354203</link>
    <description>&lt;P&gt;Is the question how to convert an Excel sheet into a SAS dataset?&lt;/P&gt;
&lt;P&gt;Or is the question once you have dataset with variables like VARNUM, NAME, TYPE, LENGTH, FORMAT and LABEL how to use that to define a SAS dataset?&lt;/P&gt;
&lt;P&gt;First convert data to ATTRIB statements.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  set specs ;
  by varnum;
  length vname vlength vformat $60 ;
  vname=nliteral(name);
  if lowcase(type)='char' then vlength=cats('length=$',length);
  else vlength=cats('length=',max(8,length));
  if format ne ' ' then vformat=cats('format=',format);
  put 'attrib ' vname&amp;nbsp;vlength&amp;nbsp;vformat&amp;nbsp;label=:$quote. ';'&amp;nbsp;;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you use %INCLUDE to use those ATTRIB statements to define the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example you could use a step like this to make an empty dataset with those variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  %include code / source2;
  call missing(of _all_);
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Sep 2023 14:08:19 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-09-29T14:08:19Z</dc:date>
    <item>
      <title>how to import data specs (excel) onto program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-data-specs-excel-onto-program/m-p/896386#M354187</link>
      <description>&lt;P&gt;Hello, Not sure if this will be a simple process, but is it fairly simple to import an excel file (eg ADSL specs) and convert them into dataset variable names, length, and label?&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="HitmonTran_0-1695975942435.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88420i385BC6DF6D44DA11/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HitmonTran_0-1695975942435.png" alt="HitmonTran_0-1695975942435.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 08:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-data-specs-excel-onto-program/m-p/896386#M354187</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2023-09-29T08:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to import data specs (excel) onto program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-data-specs-excel-onto-program/m-p/896390#M354190</link>
      <description>Ex. &lt;A href="https://youtu.be/HVfD3uJv5lc?feature=shared" target="_blank"&gt;https://youtu.be/HVfD3uJv5lc?feature=shared&lt;/A&gt;</description>
      <pubDate>Fri, 29 Sep 2023 08:48:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-data-specs-excel-onto-program/m-p/896390#M354190</guid>
      <dc:creator>JosvanderVelden</dc:creator>
      <dc:date>2023-09-29T08:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: how to import data specs (excel) onto program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-data-specs-excel-onto-program/m-p/896391#M354191</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS can read Excel files, an example taken from SAS blog&amp;nbsp;&lt;A href="https://blogs.sas.com/content/sasdummy/2015/05/20/using-libname-xlsx-to-read-and-write-excel-files/" target="_blank" rel="noopener"&gt;Using LIBNAME XLSX to read and write Excel files&lt;/A&gt;&amp;nbsp; is shown below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* because Excel field names often have spaces */
options validvarname=any;
 
libname xl XLSX '/folders/myfolders/sas_tech_talks_15.xlsx';
 
/* read in one of the tables */
data confirmed;
  set xl.confirmed;
run;
 
libname xl CLEAR;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 08:50:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-data-specs-excel-onto-program/m-p/896391#M354191</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2023-09-29T08:50:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to import data specs (excel) onto program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-data-specs-excel-onto-program/m-p/896420#M354203</link>
      <description>&lt;P&gt;Is the question how to convert an Excel sheet into a SAS dataset?&lt;/P&gt;
&lt;P&gt;Or is the question once you have dataset with variables like VARNUM, NAME, TYPE, LENGTH, FORMAT and LABEL how to use that to define a SAS dataset?&lt;/P&gt;
&lt;P&gt;First convert data to ATTRIB statements.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  set specs ;
  by varnum;
  length vname vlength vformat $60 ;
  vname=nliteral(name);
  if lowcase(type)='char' then vlength=cats('length=$',length);
  else vlength=cats('length=',max(8,length));
  if format ne ' ' then vformat=cats('format=',format);
  put 'attrib ' vname&amp;nbsp;vlength&amp;nbsp;vformat&amp;nbsp;label=:$quote. ';'&amp;nbsp;;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you use %INCLUDE to use those ATTRIB statements to define the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example you could use a step like this to make an empty dataset with those variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  %include code / source2;
  call missing(of _all_);
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 14:08:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-data-specs-excel-onto-program/m-p/896420#M354203</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-29T14:08:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to import data specs (excel) onto program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-data-specs-excel-onto-program/m-p/896462#M354218</link>
      <description>&lt;P&gt;For&amp;nbsp; your "derived" variables you may want to have someone investigate CATX instead of strip()|| strip.&lt;/P&gt;
&lt;P&gt;I have a minor concern that your derived variables are attempting to use variables that may not be defined in the order they occur. So this is likely going to take two or three passes through the junk to create appropriate attributes and the additional code that seems to be implied.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 15:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-data-specs-excel-onto-program/m-p/896462#M354218</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-09-29T15:28:08Z</dc:date>
    </item>
  </channel>
</rss>

