<?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: Delimiter not working when importing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delimiter-not-working-when-importing/m-p/945251#M370344</link>
    <description>&lt;P&gt;You probably just need to remove the N= option and the INPUT will jump to the next line when there is no more data available on the current line.&amp;nbsp; But that could be a problem if the last item on a line could be empty.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you are positive that the split between the lines always appears in the same place then just add a / to the INPUT to tell it when to move to the next line.&amp;nbsp; You could then add the TRUNCOVER option to prevent it from jumping if the last value on the line is empty.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I usually find it clearer to define the variables first with a LENGTH statement.&amp;nbsp; Then the INPUT statement can by much simpler.&amp;nbsp; And if you define the variables in the order they appear in the file you can use positional variable lists to make the INPUT statement shorter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile cards dsd dlm='|' truncover ;
  length
    SocSecNum $11 FirstInit MiddleInit LastInit $2
    CityState $35 ZipCd $5
    Gender $6 Eth $22 Racial $16 DOB 8
  ;
  input SocSecNum -- ZipCd / Gender -- DOB ;
  informat DOB date.;
  format DOB date9.;
cards;     
111-22-3333|S.|Y.|B.|Blue Mountain, Mississippi|38610                           
Male|Not Hispanic or Latino|African American|22JAN1974                          
444-55-6666|J.|G.|T.|Gulfport, Mississippi|39505                                
Male|Not Hispanic or Latino|Caucasian|22FEB1944                                 
777-88-9999|R.|Y.|H.|Gulfport, Mississippi|39505                                
Female|Not Hispanic or Latino|Caucasian|03FEB1985                               
999-88-7777|D.|W.|J.|Hollandale, Mississippi|38748                              
Female|Not Hispanic or Latino|Caucasian|22JAN1938 
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1727287832075.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100682iC18882D1B62599EA/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1727287832075.png" alt="Tom_0-1727287832075.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Sep 2024 18:12:59 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-09-25T18:12:59Z</dc:date>
    <item>
      <title>Delimiter not working when importing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delimiter-not-working-when-importing/m-p/945243#M370337</link>
      <description>&lt;P&gt;I am trying to import uncommon data that has two records per observation. SAS is reading the list vertically and not observing the delimiter. How can I fix this to import the data correctly?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached the data I am trying to import.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data HypImpt.MS_Citizens;
    infile '/home/u63991182/BIOS 6680/Hypertension Study/Data/1_Source/MS Citizens.txt' N=2 dlmstr= "|" ;
    input
        SocSecNum  :$11. 
        FirstInit  :$2. 
        MiddleInit  :$2.
        LastInit :$2.
        CityState  :$35. 
        ZipCd     :$5.
        Gender  :$6.
        Eth.  :$22.          
        Racial    :$16.  
        DOB :DATE9. ; 
    
run;

proc print data=HypImpt.MS_Citizens; 

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 17:35:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delimiter-not-working-when-importing/m-p/945243#M370337</guid>
      <dc:creator>laurenekerr</dc:creator>
      <dc:date>2024-09-25T17:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: Delimiter not working when importing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delimiter-not-working-when-importing/m-p/945247#M370341</link>
      <description>&lt;P&gt;Not a problem with the delimiter as not matching your code to the file well enough.&lt;/P&gt;
&lt;P&gt;The N=2 making two lines available still needs to be told on the INPUT which LINE to read.&lt;/P&gt;
&lt;P&gt;Plus you have an invalid variable name ETH. (with a period)&lt;/P&gt;
&lt;P&gt;Your INPUT statement should look like:&lt;/P&gt;
&lt;PRE&gt;    input
        SocSecNum  :$11. 
        FirstInit  :$2. 
        MiddleInit  :$2.
        LastInit :$2.
        CityState  :$35. 
        ZipCd     :$5.
       / Gender  :$6.
        Eth  :$22.          
        Racial    :$16.  
        DOB :DATE9. 
      ; 
&lt;/PRE&gt;
&lt;P&gt;The / says "read on next line" . Or instead of / you could use #2, which means "read on line 2 of the available lines".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is a single character I would prefer to use DLM instead of DLMSTR but not an error just a style choice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 17:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delimiter-not-working-when-importing/m-p/945247#M370341</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-09-25T17:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Delimiter not working when importing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delimiter-not-working-when-importing/m-p/945251#M370344</link>
      <description>&lt;P&gt;You probably just need to remove the N= option and the INPUT will jump to the next line when there is no more data available on the current line.&amp;nbsp; But that could be a problem if the last item on a line could be empty.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you are positive that the split between the lines always appears in the same place then just add a / to the INPUT to tell it when to move to the next line.&amp;nbsp; You could then add the TRUNCOVER option to prevent it from jumping if the last value on the line is empty.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I usually find it clearer to define the variables first with a LENGTH statement.&amp;nbsp; Then the INPUT statement can by much simpler.&amp;nbsp; And if you define the variables in the order they appear in the file you can use positional variable lists to make the INPUT statement shorter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile cards dsd dlm='|' truncover ;
  length
    SocSecNum $11 FirstInit MiddleInit LastInit $2
    CityState $35 ZipCd $5
    Gender $6 Eth $22 Racial $16 DOB 8
  ;
  input SocSecNum -- ZipCd / Gender -- DOB ;
  informat DOB date.;
  format DOB date9.;
cards;     
111-22-3333|S.|Y.|B.|Blue Mountain, Mississippi|38610                           
Male|Not Hispanic or Latino|African American|22JAN1974                          
444-55-6666|J.|G.|T.|Gulfport, Mississippi|39505                                
Male|Not Hispanic or Latino|Caucasian|22FEB1944                                 
777-88-9999|R.|Y.|H.|Gulfport, Mississippi|39505                                
Female|Not Hispanic or Latino|Caucasian|03FEB1985                               
999-88-7777|D.|W.|J.|Hollandale, Mississippi|38748                              
Female|Not Hispanic or Latino|Caucasian|22JAN1938 
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1727287832075.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100682iC18882D1B62599EA/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1727287832075.png" alt="Tom_0-1727287832075.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 18:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delimiter-not-working-when-importing/m-p/945251#M370344</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-25T18:12:59Z</dc:date>
    </item>
  </channel>
</rss>

