<?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: Datastep Input for Variable Names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Datastep-Input-for-Variable-Names/m-p/50318#M10495</link>
    <description>why not import first then doing the cleaning, &lt;BR /&gt;
or you can use some macro, or functions such as varname() varn()(may not exactly , you can check in help)</description>
    <pubDate>Tue, 30 Sep 2008 03:58:40 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-09-30T03:58:40Z</dc:date>
    <item>
      <title>Datastep Input for Variable Names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datastep-Input-for-Variable-Names/m-p/50316#M10493</link>
      <description>I'm using a datastep to import a csv into SAS.  The data needs some cleansing so I'm unable to get the data in through proc import.  But I really want to use a feature that is used in proc import: Not knowing the variable names or number of variables in advance.  Is there an option that allows the first line of the input command to serve as variable names? or is there a special command ie: vinput that allows you to read in the variable names?&lt;BR /&gt;
&lt;BR /&gt;
thanks&lt;BR /&gt;
johnny</description>
      <pubDate>Mon, 29 Sep 2008 21:36:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datastep-Input-for-Variable-Names/m-p/50316#M10493</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-09-29T21:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: Datastep Input for Variable Names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datastep-Input-for-Variable-Names/m-p/50317#M10494</link>
      <description>It would be most useful for you to share an example of your challenging input data and how you would like it to be interpreted by SAS.  &lt;BR /&gt;
&lt;BR /&gt;
Also, you mention "...option that allows the first line of the input command to serve as variable names?"  Can you explain "input command" -- did you mean input file?  If so, there is a "PROC IMPORT" parameter you can code to tell SAS to use the first data row as the variable names.&lt;BR /&gt;
&lt;BR /&gt;
In addition to hosting the SAS product documentation, there are numerous SAS technical papers on all sorts of topics, available at the SAS support website   &lt;A href="http://support.sas.com" target="_blank"&gt;http://support.sas.com&lt;/A&gt; .  I did a search and found the SAS technical reference below on PROC IMPORT, along with the DOC links provided.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
SAS Technical document on PROC IMPORT:&lt;BR /&gt;
ftp://ftp.sas.com/techsup/download/sample/datastep/import.html&lt;BR /&gt;
&lt;BR /&gt;
SAS PROC IMPORT DOC on Data Source statements:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/proc/59565/HTML/default/a000312413.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/59565/HTML/default/a000312413.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
SAS Support website DOC page:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/onlinedoc/base/index.html" target="_blank"&gt;http://support.sas.com/documentation/onlinedoc/base/index.html&lt;/A&gt;</description>
      <pubDate>Mon, 29 Sep 2008 23:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datastep-Input-for-Variable-Names/m-p/50317#M10494</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-09-29T23:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: Datastep Input for Variable Names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datastep-Input-for-Variable-Names/m-p/50318#M10495</link>
      <description>why not import first then doing the cleaning, &lt;BR /&gt;
or you can use some macro, or functions such as varname() varn()(may not exactly , you can check in help)</description>
      <pubDate>Tue, 30 Sep 2008 03:58:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datastep-Input-for-Variable-Names/m-p/50318#M10495</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-09-30T03:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Datastep Input for Variable Names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datastep-Input-for-Variable-Names/m-p/50319#M10496</link>
      <description>I was searching for some kind of %csv2ds macro - but couldn't find anything. I'm almost sure searching with some more patiance would bring a result.&lt;BR /&gt;
&lt;BR /&gt;
If you want to solve it by yourself then you'll end up in some serious programming.&lt;BR /&gt;
It's not only about getting the names for variables, it's also about getting the type and length - and this means first scanning the first x rows and see what data you've got (proc import has also to do something like that).&lt;BR /&gt;
Once you've got that all you could build a macro variable with the necessary input statement and then just use this macrovar in a dataset, i.e:&lt;BR /&gt;
&lt;BR /&gt;
data readall;&lt;BR /&gt;
  input &amp;amp;inputlist;&lt;BR /&gt;
  ....&lt;BR /&gt;
&lt;BR /&gt;
But as I said: Creating the value for this macrovar means some programming. Better use proc import and cleanse/recode the variables afterwards.&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Tue, 30 Sep 2008 12:02:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datastep-Input-for-Variable-Names/m-p/50319#M10496</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2008-09-30T12:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: Datastep Input for Variable Names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datastep-Input-for-Variable-Names/m-p/50320#M10497</link>
      <description>Thanks for everyone's input.&lt;BR /&gt;
&lt;BR /&gt;
To answer a couple of your questions:&lt;BR /&gt;
&lt;BR /&gt;
sbb- &lt;BR /&gt;
&amp;gt;&amp;gt;&amp;gt;"...option that allows the first line of the input command to serve as variable names." &lt;BR /&gt;
&amp;lt;&amp;lt;&amp;lt;"...did you mean input file."&lt;BR /&gt;
I didn't really mean input file but yes the first line of the input file is used by proc import, read in, stored as variable names, and assigns the datatype and length based on the second line of the input file.  when I run proc import my log produces the "underlying" datastep...with all of the variable names. how does it get them?&lt;BR /&gt;
&lt;BR /&gt;
I'd love to use proc import then do the cleansing the difficulty is that the input file has 8 lines of header information 3 blank lines, 1 line for data title (inventory) then a data table, including variable names and ended with a TOTAL line.  Then there are 3 more blank lines another line for data table title (cost) and another data table.  This continues on and on for about 15 variables...yeah 15 data tables in one csv.  There is too much going on in the file for proc import to handle the data correctly...as far as I know.  I'd like each of the 15 data tables in the CSV to become a seperate and uniquely named dataset in SAS...as you'll see in the code below.&lt;BR /&gt;
&lt;BR /&gt;
Patrick - you nailed my issue.  If the first line of data I import is the variable name it sets my variable type and length to strings of that length...which is not at all what i need.  Then since I do not know the name of those variables (since each table is different) I'm unable to attempt data transformations.&lt;BR /&gt;
&lt;BR /&gt;
lastly, I imagine with some extensive macro programming and looping I could power this out..as you can see I've already done some of below...but I try to work under the premise that if I have to work hard to do something that is easy (ie for proc import) then I probably don't know something that I should.&lt;BR /&gt;
&lt;BR /&gt;
here is the code that is currently importing my data.&lt;BR /&gt;
&lt;BR /&gt;
data outlib.&amp;amp;MakeSet;&lt;BR /&gt;
   length RowNav $ 50; &lt;BR /&gt;
   drop Count;&lt;BR /&gt;
   infile %UNQUOTE(&amp;amp;InFilePath&amp;amp;InFileName&amp;amp;InFileIndex&amp;amp;CSV) dlm=',' &lt;BR /&gt;
      missover lrecl=1000;&lt;BR /&gt;
   input RowNav;  *row navigation variable indicating where I'm at in the file;&lt;BR /&gt;
   if RowNav=%UNQUOTE(&amp;amp;&amp;amp;Trigger&amp;amp;MakeSet) then do; *macro triggers based&lt;BR /&gt;
         data title;&lt;BR /&gt;
      array Temp{&amp;amp;NumMonths} $25.;&lt;BR /&gt;
      do until (RowNav = &amp;amp;&amp;amp;End&amp;amp;MakeSet); *macro trigger for TOTAL line (last row);&lt;BR /&gt;
         input RowNav $ @;&lt;BR /&gt;
         do Count=1 to &amp;amp;NumMonths-1; *previously determined number of columns;&lt;BR /&gt;
            input Temp(Count) @;&lt;BR /&gt;
            if Temp(Count) = '' then Temp(Count) = 0;&lt;BR /&gt;
         end;&lt;BR /&gt;
         input Temp(&amp;amp;NumMonths);&lt;BR /&gt;
         output;&lt;BR /&gt;
      end;&lt;BR /&gt;
   end;&lt;BR /&gt;
   else delete;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Again thanks for everyone's input...i'm looking into your suggestions.&lt;BR /&gt;
johnny</description>
      <pubDate>Tue, 30 Sep 2008 23:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datastep-Input-for-Variable-Names/m-p/50320#M10497</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-09-30T23:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Datastep Input for Variable Names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datastep-Input-for-Variable-Names/m-p/50321#M10498</link>
      <description>Hi:&lt;BR /&gt;
  Before you try to reinvent the wheel, this Tech support note (found by searching support.sas.com)&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/13/735.html" target="_blank"&gt;http://support.sas.com/kb/13/735.html&lt;/A&gt;&lt;BR /&gt;
  &lt;BR /&gt;
  ... describes a program called rangeimporter.sas, which, according to the note:&lt;B&gt;&lt;BR /&gt;
"The rangeimporter9.sas program can import ranges of Excel data that do not include the first row or column and retain the column names. " &lt;/B&gt;&lt;BR /&gt;
 &lt;BR /&gt;
Maybe that program can help you do what you want to do.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 01 Oct 2008 18:54:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datastep-Input-for-Variable-Names/m-p/50321#M10498</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-10-01T18:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: Datastep Input for Variable Names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datastep-Input-for-Variable-Names/m-p/50322#M10499</link>
      <description>Cynthia, awesome...I'll check it out.  Thanks as always.</description>
      <pubDate>Wed, 01 Oct 2008 19:59:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datastep-Input-for-Variable-Names/m-p/50322#M10499</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-01T19:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: Datastep Input for Variable Names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datastep-Input-for-Variable-Names/m-p/50323#M10500</link>
      <description>Hi Johnny&lt;BR /&gt;
After your clarifications I think what you're looking for is solved within the current Proc Import (it used to be different). Have a look at: &lt;A href="http://support.sas.com/onlinedoc/913/getDoc/en/proc.hlp/a000312413.htm" target="_blank"&gt;http://support.sas.com/onlinedoc/913/getDoc/en/proc.hlp/a000312413.htm&lt;/A&gt;&lt;BR /&gt;
especially "Getnames" and "Guessingrows"&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Thu, 02 Oct 2008 12:01:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datastep-Input-for-Variable-Names/m-p/50323#M10500</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2008-10-02T12:01:43Z</dc:date>
    </item>
  </channel>
</rss>

