<?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: Adding a space in a specific location to character string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-space-in-a-specific-location-to-character-string/m-p/256220#M49062</link>
    <description>&lt;P&gt;TIME8. comes from &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000197899.htm" target="_self"&gt;this source&lt;/A&gt;, which identifies it as an Informat. What am I missing?&lt;/P&gt;</description>
    <pubDate>Fri, 11 Mar 2016 21:02:31 GMT</pubDate>
    <dc:creator>_maldini_</dc:creator>
    <dc:date>2016-03-11T21:02:31Z</dc:date>
    <item>
      <title>Adding a space in a specific location to character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-space-in-a-specific-location-to-character-string/m-p/256189#M49048</link>
      <description>&lt;P&gt;I have a dataset w/ times stored as character strings. In some strings, there is a space between the trailing number, usually 0, and the AM/PM designation (e.g. 10:00 PM). In others, there is no space (8:00PM).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I create consistency in these data so that there is a space after the time and before the AM/PM designation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obs _300101 _300102 _300201 _300202&lt;BR /&gt;1 8:00PM 10:00 PM 4:00 AM 9:00AM&lt;BR /&gt;2 1:00 AM 2:00 AM 10:00 AM 12:00 PM&lt;BR /&gt;3 12:00AM 11:30AM 8:00AM 6:30AM&lt;BR /&gt;4 12:00 AM 2:00 AM 6:00 AM 11:00 AM&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2016 18:50:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-space-in-a-specific-location-to-character-string/m-p/256189#M49048</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-03-11T18:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a space in a specific location to character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-space-in-a-specific-location-to-character-string/m-p/256194#M49051</link>
      <description>&lt;P&gt;Don't store them as character strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use Input to convert them to time variables and then format them as time variables.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2016 19:30:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-space-in-a-specific-location-to-character-string/m-p/256194#M49051</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-11T19:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a space in a specific location to character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-space-in-a-specific-location-to-character-string/m-p/256206#M49057</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&amp;nbsp;Could you help me do that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not having success assigning informats to the data (See code).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA timedata_a1_a5 ;
INFILE "/folders/myfolders/XXXX/XXXX/! Datasets/Original Datasets/Time Data A1-A5.csv" DLM="," DSD TERMSTR=CR;
INPUT 	PATIENTID a1_300101  TIME8. a1_300102	TIME8. a1_300201  TIME8. a1_300202  TIME8.;
RUN;&lt;/PRE&gt;
&lt;P&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;BR /&gt; 55 &lt;BR /&gt; 56 DATA timedata_a1_a5 ;&lt;BR /&gt; 57 INFILE "/folders/myfolders/XXX/XXX/! Datasets/Original Datasets/Time Data A1-A5.csv" DLM="," DSD TERMSTR=CR;&lt;BR /&gt; 58 INPUT PATIENTID&lt;BR /&gt; 59 a1_300101 TIME8. a1_300102TIME8. a1_300201 TIME8. a1_300202 TIME8. ;&lt;BR /&gt; 60 RUN;&lt;BR /&gt; &lt;BR /&gt; NOTE: The infile "/folders/myfolders/UCSD/SMART/! Datasets/Original Datasets/Time Data A1-A5.csv" is:&lt;BR /&gt; Filename=/folders/myfolders/UCSD/SMART/! Datasets/Original Datasets/Time Data A1-A5.csv,&lt;BR /&gt; Owner Name=root,Group Name=vboxsf,&lt;BR /&gt; Access Permission=-rwxrwx---,&lt;BR /&gt; Last Modified=11Mar2016:12:04:45,&lt;BR /&gt; File Size (bytes)=60019&lt;BR /&gt; &lt;BR /&gt; NOTE: Invalid data for a1_300102 in line 1 12-19.&lt;BR /&gt; NOTE: Invalid data for a1_300201 in line 1 20-27.&lt;BR /&gt; NOTE: Invalid data for a1_300202 in line 1 28-35.&lt;BR /&gt; RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 &lt;BR /&gt; 1 26,11:00 PM,01:00 AM,09:00 AM,10:30 AM,9:00 PM,10:00 PM,10:00 AM,8:30 AM,10:00 PM,11:00 PM,7:00 AM,8&lt;BR /&gt; 101 :00 AM,8:00 PM,10:00 PM,4:00 AM,9:00 AM,10:00 PM,12:00 AM,4:30 AM,9:00 AM 173&lt;BR /&gt; PATIENTID=26 a1_300101=82800 a1_300102=. a1_300201=. a1_300202=. _ERROR_=1 _N_=1&lt;BR /&gt; NOTE: Invalid data for a1_300101 in line 2 4-11.&lt;BR /&gt; NOTE: Invalid data for a1_300201 in line 2 20-27.&lt;BR /&gt; NOTE: Invalid data for a1_300202 in line 2 28-35.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Etc...&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2016 20:27:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-space-in-a-specific-location-to-character-string/m-p/256206#M49057</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-03-11T20:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a space in a specific location to character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-space-in-a-specific-location-to-character-string/m-p/256211#M49059</link>
      <description>&lt;P&gt;You don't have an informat statement in that code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe start there?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2016 20:42:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-space-in-a-specific-location-to-character-string/m-p/256211#M49059</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-11T20:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a space in a specific location to character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-space-in-a-specific-location-to-character-string/m-p/256220#M49062</link>
      <description>&lt;P&gt;TIME8. comes from &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000197899.htm" target="_self"&gt;this source&lt;/A&gt;, which identifies it as an Informat. What am I missing?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2016 21:02:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-space-in-a-specific-location-to-character-string/m-p/256220#M49062</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-03-11T21:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a space in a specific location to character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-space-in-a-specific-location-to-character-string/m-p/256224#M49063</link>
      <description>Informat variable1 time8. ;&lt;BR /&gt;Don't place the format on the input line, use its own line of code, as above.</description>
      <pubDate>Fri, 11 Mar 2016 21:10:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-space-in-a-specific-location-to-character-string/m-p/256224#M49063</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-11T21:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a space in a specific location to character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-space-in-a-specific-location-to-character-string/m-p/256251#M49072</link>
      <description>&lt;P&gt;So now that I can type on a full computer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A full data step import contains the following statements (see code below). You only have the input/infile statements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add in an informat and format to control how your data comes in and is displayed. It's cumbersome and annoying as heck, which is why I suggested proc import and then modifying the code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having spent the last 2 hours developing code to read in a file that didn't have appropriate documentation I understand your pain :).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Doing it this way will save you a lot of issues down the road...and many questions on here :).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good Luck!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data want;

informat ****;

format ****;

infile ***;

input ***;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Mar 2016 23:27:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-space-in-a-specific-location-to-character-string/m-p/256251#M49072</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-11T23:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a space in a specific location to character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-space-in-a-specific-location-to-character-string/m-p/256268#M49079</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Obs (_300101 _300102 _300201 _300202) (&amp;amp; $40.);
cards;
1 8:00PM   10:00 PM   4:00 AM   9:00AM
2 1:00 AM  2:00 AM   10:00 AM   12:00 PM
3 12:00AM  11:30AM   8:00AM    6:30AM
4 12:00 AM  2:00 AM   6:00 AM   11:00 AM
;
run;
data want;
 set have;
 array x{*} $ _:;
 array y{4} $ 40;
 do i=1 to dim(x);
  y{i}=prxchange('s/\s*(am|pm)$/ $1/i',-1,strip(x{i}));
 end;
 drop i;
run;
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 12 Mar 2016 06:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-space-in-a-specific-location-to-character-string/m-p/256268#M49079</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-12T06:29:42Z</dc:date>
    </item>
  </channel>
</rss>

