<?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 dashes to replace missing values in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Adding-dashes-to-replace-missing-values/m-p/697260#M25362</link>
    <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/New-SAS-User/How-to-use-FML-initial-format/m-p/694369" target="_blank"&gt;https://communities.sas.com/t5/New-SAS-User/How-to-use-FML-initial-format/m-p/694369&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Say hello to your classmates.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 06 Nov 2020 22:20:07 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-11-06T22:20:07Z</dc:date>
    <item>
      <title>Adding dashes to replace missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-dashes-to-replace-missing-values/m-p/697256#M25358</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;I am working in SAS studio for SAS On Demand. I am working on a project for class and need help adding in dashes in place of missing values for the variable 'Inits'. Some of the observations have missing middle initials and they are blanks, one example is observation #6 below, and I need those to be dashes. I have attached the original dataset, along with my code to manipulate it, and a screenshot of the results.&lt;/P&gt;
&lt;P&gt;Code:&lt;/P&gt;
&lt;P&gt;DATA Utah;&lt;BR /&gt;retain SSN Inits City StateCd ZipCd;&lt;BR /&gt;SET Records (rename = (Inits = Initsold&lt;BR /&gt;CitySt = StateCd));&lt;BR /&gt;ID1 = put(ID, Z9.);&lt;BR /&gt;SSN = catx('-', SUBSTR(PUT(ID1, Z9.), 1, 3), SUBSTR(PUT(ID1, Z9.), 4, 2), SUBSTR(PUT(ID1, Z9.), 6, 4));&lt;BR /&gt;ZipCd = put(Zipcode, Z5.);&lt;BR /&gt;City = scan(StateCd, 1, ',');&lt;BR /&gt;Inits = compress(Initsold,'.');&lt;BR /&gt;&lt;BR /&gt;***note: how would I add in a dash for missing middle initial?;&lt;BR /&gt;&lt;BR /&gt;drop ID ID1 Zipcode Initsold GenderCode EthnicityCode RaceCode BirthYear BirthMonth BirthDay;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know if anyone knows what to do! Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sincerely,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kaitlin E Buck&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 15:10:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-dashes-to-replace-missing-values/m-p/697256#M25358</guid>
      <dc:creator>kateb409</dc:creator>
      <dc:date>2020-12-10T15:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: Adding dashes to replace missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-dashes-to-replace-missing-values/m-p/697257#M25359</link>
      <description>&lt;P&gt;Only for missing middle initial, correct?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2020 22:02:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-dashes-to-replace-missing-values/m-p/697257#M25359</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-06T22:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: Adding dashes to replace missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-dashes-to-replace-missing-values/m-p/697259#M25361</link>
      <description>&lt;P&gt;I would start with&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Inits = coalescec ( compress(Initsold,'.'), '-');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The coalsecec (and the numeric coalesce) functions examine the values inside the () from left to right and return the leftmost non-missing value. So if compress(initsold,'.') returns missing the coalescec looks at the next value and gets the dash (or any other character value you have there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your ID variable is numeric you could assign the SSN. format to it so values display&amp;nbsp; in the 123-45-6789.&lt;/P&gt;
&lt;P&gt;Or use&lt;/P&gt;
&lt;P&gt;SSN = put(id,ssn.); instead of messing around with all that substr code.&lt;/P&gt;
&lt;PRE&gt;data  example;
   x= 123456789;
   ssn = put(x,ssn.);
   put ssn=;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Nov 2020 22:12:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-dashes-to-replace-missing-values/m-p/697259#M25361</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-06T22:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: Adding dashes to replace missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-dashes-to-replace-missing-values/m-p/697260#M25362</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/New-SAS-User/How-to-use-FML-initial-format/m-p/694369" target="_blank"&gt;https://communities.sas.com/t5/New-SAS-User/How-to-use-FML-initial-format/m-p/694369&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Say hello to your classmates.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2020 22:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-dashes-to-replace-missing-values/m-p/697260#M25362</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-11-06T22:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: Adding dashes to replace missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-dashes-to-replace-missing-values/m-p/697344#M25384</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, it is only for the middle initials.&lt;/P&gt;&lt;P&gt;-Kaitlin&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2020 15:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-dashes-to-replace-missing-values/m-p/697344#M25384</guid>
      <dc:creator>kateb409</dc:creator>
      <dc:date>2020-11-07T15:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Adding dashes to replace missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-dashes-to-replace-missing-values/m-p/697345#M25385</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I checked this out and this post is actually about a different part of a project my class is working on. My issue is that for the dataset I have attached is there are missing values (as blanks) for middle initials in some of the observations and they need to be dashes not blanks. The post you referred me to is about keeping dashes as missing middle initials in a different dataset.&lt;/P&gt;&lt;P&gt;-Kaitlin&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2020 15:29:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-dashes-to-replace-missing-values/m-p/697345#M25385</guid>
      <dc:creator>kateb409</dc:creator>
      <dc:date>2020-11-07T15:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Adding dashes to replace missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-dashes-to-replace-missing-values/m-p/697349#M25386</link>
      <description>&lt;P&gt;So first let's look at the code you posted and see what it is doing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.Contact_UT;
  retain SSN Inits City StateCd ZipCd;
  SET HypImpt.UT_Records (rename=(Inits=Initsold CitySt=StateCd));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So those lines will create a new dataset named CONTACT_UT in the WORK library by reading the data from the exiting UT_RECORDS dataset in the HYPIMPT library.&amp;nbsp; Two of the variables will have their names changed. Plus five variables will be forced to the beginning of the column order (and if they weren't already on the input dataset the automatic reset to missing at the start of each iteration of the data step will be cancelled.)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ID1 = put(ID, Z9.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will convert the numeric variable ID to a new character variable ID1.&amp;nbsp; Since you haven't yet defined ID1 SAS will guess that you meant to make it character of length 9 because of the width of the format used in the PUT() function call.&amp;nbsp; If ID is not numeric it will first be converted by SAS to a number, and any values that don't look like numbers will cause a missing value to be used in the PUT() function call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SSN = catx('-', SUBSTR(PUT(ID1, Z9.), 1, 3), SUBSTR(PUT(ID1, Z9.), 4, 2), SUBSTR(PUT(ID1, Z9.), 6, 4));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This statement does not make any sense. This part, PUT(ID1, Z9.), of that statement does not make any sense.&amp;nbsp; It will take the value of the new CHARACTER variable ID1 and try to convert to a number (note that SAS uses the BEST12 format to do this automatic conversion. Since the number is at most 9 digits long the first three characters will always be spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ZipCd = put(Zipcode, Z5.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is similar to the previous code.&amp;nbsp; Since ZIPCD is not previously defined SAS will guess that you want to define is as character with a length of 5.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;City = scan(StateCd, 1, ',');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will take the values of STATECD, what used to called CITYCD, up to the first comma and put it into CITY. If CITY does not already exist then SAS will guess that you want it to have the same length of STATECD does.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Inits = compress(Initsold,'.');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This line will remove any periods from INITSOLD, what used to be named INITS, and assign it to INITS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  drop ID ID1 Zipcode Initsold GenderCode EthnicityCode RaceCode BirthYear BirthMonth BirthDay;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And finally you list which variable not to keep in the target dataset.&amp;nbsp; Any other variables generated by the data step will be in the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just want to convert periods to hyphens you can use the TRANSLATE() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Inits = translate(Initsold,'-','.');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For more help post some of the data as TEXT (not attached binary files or photographs).&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2020 17:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-dashes-to-replace-missing-values/m-p/697349#M25386</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-07T17:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Adding dashes to replace missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-dashes-to-replace-missing-values/m-p/697355#M25388</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/New-SAS-User/How-to-use-FML-initial-format/m-p/694369" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/New-SAS-User/How-to-use-FML-initial-format/m-p/694369&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Say hello to your classmates.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have seen a similar dataset structure in posts by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/344745"&gt;@neeloofar&lt;/a&gt;&amp;nbsp;, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349942"&gt;@Krissy217&lt;/a&gt;&amp;nbsp;and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350113"&gt;@rodrima4&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2020 18:06:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-dashes-to-replace-missing-values/m-p/697355#M25388</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-07T18:06:25Z</dc:date>
    </item>
  </channel>
</rss>

