<?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: Help with formatting, getting rid of the first variable when using length in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Help-with-formatting-getting-rid-of-the-first-variable-when/m-p/684061#M24191</link>
    <description>&lt;P&gt;Add the statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DELIMITER = '|';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to proc import.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Sep 2020 20:11:27 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2020-09-15T20:11:27Z</dc:date>
    <item>
      <title>Help with formatting, getting rid of the first variable when using length</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-formatting-getting-rid-of-the-first-variable-when/m-p/684039#M24188</link>
      <description>&lt;P&gt;Hello. When I import a file there's an automatic var1 that appears, but when I try to use a formatting statement it doesn't use the observations in the first variable, instead it reads nothing and erases the observations in the first variable, as well as the name, but there's still a space for it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I'm using:&lt;/P&gt;&lt;P&gt;Proc import datafile= 'Y:\SAS\Political_Party.txt'&lt;BR /&gt;out= politicalparty&lt;BR /&gt;replace;&lt;BR /&gt;getnames=no;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/this gives me all the observations in the set/;&lt;BR /&gt;data mylib.politicalparty;&lt;BR /&gt;set politicalparty;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.politicalparty;&lt;BR /&gt;set politicalparty;&lt;BR /&gt;Length&lt;BR /&gt;gender $1&lt;BR /&gt;party $2&lt;BR /&gt;vote 3&lt;BR /&gt;foreign 4&lt;BR /&gt;spend 5;&lt;BR /&gt;label&lt;BR /&gt;gender= 'Gender'&lt;BR /&gt;party='Political Party'&lt;BR /&gt;vote='Did you vote in the last election?'&lt;BR /&gt;foreign="Do you agree with the government's foreign policy?"&lt;BR /&gt;spend= 'Should we increase domestic spending?';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for reading.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2020 19:26:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-formatting-getting-rid-of-the-first-variable-when/m-p/684039#M24188</guid>
      <dc:creator>Diana__</dc:creator>
      <dc:date>2020-09-15T19:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: Help with formatting, getting rid of the first variable when using length</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-formatting-getting-rid-of-the-first-variable-when/m-p/684043#M24189</link>
      <description>&lt;P&gt;It would be best to copy a few lines from the text file paste them into a code box opened on the forum using the &amp;lt;/&amp;gt; icon. The code box is important because that will preserve the file format better. The main message windows will modify text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code you use with the getnames=no is possibly an issue if you expect to get variable names from the column headers. That option says not to.&lt;/P&gt;
&lt;PRE&gt;Proc import datafile= 'Y:\SAS\Political_Party.txt'
out= politicalparty
replace;
getnames=no;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2020 19:42:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-formatting-getting-rid-of-the-first-variable-when/m-p/684043#M24189</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-15T19:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: Help with formatting, getting rid of the first variable when using length</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-formatting-getting-rid-of-the-first-variable-when/m-p/684049#M24190</link>
      <description>&lt;P&gt;Thank you very much for replying so quickly!&lt;/P&gt;&lt;P&gt;There are no names at the top of the text document I'm importing, if I don't use that statement then I only get 12/14 of the observations. There are no missing values or anything, an example of how it looks after the import is here (It's on a different computer so I'm sorry for the lack of pictures):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(obs. #) l&amp;nbsp;&amp;nbsp;&amp;nbsp; VAR1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l Gender l (etc.)&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l 007MR110 l&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l 013FD101 l&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: I have added the ID to the beginning now, it covers rows 1-3. It now has the data in the first column, but not any of the others.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2020 19:54:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-formatting-getting-rid-of-the-first-variable-when/m-p/684049#M24190</guid>
      <dc:creator>Diana__</dc:creator>
      <dc:date>2020-09-15T19:54:03Z</dc:date>
    </item>
    <item>
      <title>Re: Help with formatting, getting rid of the first variable when using length</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-formatting-getting-rid-of-the-first-variable-when/m-p/684061#M24191</link>
      <description>&lt;P&gt;Add the statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DELIMITER = '|';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to proc import.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2020 20:11:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-formatting-getting-rid-of-the-first-variable-when/m-p/684061#M24191</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-09-15T20:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: Help with formatting, getting rid of the first variable when using length</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-formatting-getting-rid-of-the-first-variable-when/m-p/684188#M24197</link>
      <description>Your example file looks a little odd, the delimiters you are using are "l" (lower case letter L) at least in the post. &lt;BR /&gt;Still what PGStats suggests is correct you need to define the delimiter be that a lower case L or whatever the delimiter is.</description>
      <pubDate>Wed, 16 Sep 2020 12:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-formatting-getting-rid-of-the-first-variable-when/m-p/684188#M24197</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2020-09-16T12:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: Help with formatting, getting rid of the first variable when using length</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-formatting-getting-rid-of-the-first-variable-when/m-p/684325#M24205</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/347343"&gt;@Diana__&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you very much for replying so quickly!&lt;/P&gt;
&lt;P&gt;There are no names at the top of the text document I'm importing, if I don't use that statement then I only get 12/14 of the observations. There are no missing values or anything&lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt;, an example of how it looks &lt;U&gt;after&lt;/U&gt; the import is here&lt;/STRONG&gt;&lt;/FONT&gt; (It's on a different computer so I'm sorry for the lack of pictures):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(obs. #) l&amp;nbsp;&amp;nbsp;&amp;nbsp; VAR1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l Gender l (etc.)&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l 007MR110 l&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l&lt;/P&gt;
&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l 013FD101 l&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: I have added the ID to the beginning now, it covers rows 1-3. It now has the data in the first column, but not any of the others.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;We need to know what the file looks like &lt;STRONG&gt;BEFORE &lt;/STRONG&gt;importing the file since your issue involves reading the file. To do that we need actual text of the file. Pictures do not work as we can't write to code to read a picture.&lt;/P&gt;
&lt;P&gt;That means open the file with a plain text editor of some sort, such as NotePad, copy 4 or 5 lines of text and then on the forum open a code box using the &amp;lt;/&amp;gt; icon and then paste the text. The code box is &lt;STRONG&gt;critical&lt;/STRONG&gt; because the message windows will reformat text and often removes blanks and inserts html tags so that what is in a main window is NOT what is in your file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 17:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-formatting-getting-rid-of-the-first-variable-when/m-p/684325#M24205</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-16T17:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Help with formatting, getting rid of the first variable when using length</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-formatting-getting-rid-of-the-first-variable-when/m-p/684336#M24206</link>
      <description>&lt;P&gt;There is no reason to use PROC IMPORT to read a text. Especially if you the file does not have even a header row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So just start with a data step that reads the file.&amp;nbsp; So something like this. The LENGTH of a SAS variable is how many byte sit takes in the SAS dataset, it has almost nothign to do with how many characters it takes to display it as text in file. SAS stores numbers as 8 byte floating point values.&amp;nbsp; So there is no reason the set lengths of numeric variables to anything other than 8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your program might just be something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mylib.politicalparty;
  infile 'Y:\SAS\Political_Party.txt' dsd dlm='|' truncover ;
  length
    gender $1
    party $2
    vote 8
    foreign 8
    spend 8
  ;
  input gender -- spend ;
  label 
    gender= 'Gender'
    party='Political Party'
    vote='Did you vote in the last election?'
    foreign="Do you agree with the government's foreign policy?"
    spend= 'Should we increase domestic spending?'
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Sep 2020 18:18:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-formatting-getting-rid-of-the-first-variable-when/m-p/684336#M24206</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-09-16T18:18:01Z</dc:date>
    </item>
  </channel>
</rss>

