<?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: How to use if-then with characters in SAS? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-if-then-with-characters-in-SAS/m-p/117836#M293182</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;contain 26 or equal 26? there may be leading or trailing blacks. try:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12.800000190734863px; background-color: #ffffff;"&gt; if strip(mod_1) = '26' then modifier = '26';&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Jul 2012 22:08:40 GMT</pubDate>
    <dc:creator>Linlin</dc:creator>
    <dc:date>2012-07-25T22:08:40Z</dc:date>
    <item>
      <title>How to use if-then with characters in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-if-then-with-characters-in-SAS/m-p/117833#M293179</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to use an if-then statement with a variable character. I am running into a problem though where every time I run my code, the system converts my character variables into numeric variables and then defaults to the else statement. What I have is a multitude of characters from a large dataset. I only want to keep values that are 00, 26 or TC with everything else becoming 00. I initially tried the single quote since I thought that was used for characters, and then no quotes but both times everything has defaulted to 00. Here is the portion of the code that I am currently working on:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data rs0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set detail;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if mod_1 = '00' then modifier = '00';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if mod_1 = '26' then modifier = '26';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if mod_1 = 'TC' then modifier = 'TC';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else modifier = '00';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data=rs0 label;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; label&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; modifier = "Modifier";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is some sorting and univariate commands between this, but I left the specific portion that I cannot get correct. If anyone could help me clear this up; it would be greatly appreciated. Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jul 2012 20:27:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-if-then-with-characters-in-SAS/m-p/117833#M293179</guid>
      <dc:creator>Torri92</dc:creator>
      <dc:date>2012-07-25T20:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to use if-then with characters in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-if-then-with-characters-in-SAS/m-p/117834#M293180</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You may need to run proc contents on your data set to see if the variables are actually numeric or not. Does MODIFIER already exist in the dataset as well?&lt;/P&gt;&lt;P&gt;Single or double quotes will work for delimiting strings.&lt;/P&gt;&lt;P&gt;Proc freq data=rs0; table mod_1;run; may be of interest. It could be that you actually don't have the values of 26 or TC in mod_1;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jul 2012 21:02:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-if-then-with-characters-in-SAS/m-p/117834#M293180</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2012-07-25T21:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to use if-then with characters in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-if-then-with-characters-in-SAS/m-p/117835#M293181</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm away from the server which has SAS loaded onto it but I'm almost certain that mod_1 is a character string. MODIFIER does NOT already exist in the dataset. My thought process was that the if-then statement would create a new variable so I gave it a unique name. There are a couple hundred codes which contain 26 or TC so I know that they do exist. I'll try the proc freq command when I get back to the server tomorrow. Thank you for your advice.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jul 2012 21:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-if-then-with-characters-in-SAS/m-p/117835#M293181</guid>
      <dc:creator>Torri92</dc:creator>
      <dc:date>2012-07-25T21:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to use if-then with characters in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-if-then-with-characters-in-SAS/m-p/117836#M293182</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;contain 26 or equal 26? there may be leading or trailing blacks. try:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12.800000190734863px; background-color: #ffffff;"&gt; if strip(mod_1) = '26' then modifier = '26';&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jul 2012 22:08:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-if-then-with-characters-in-SAS/m-p/117836#M293182</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-07-25T22:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to use if-then with characters in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-if-then-with-characters-in-SAS/m-p/117837#M293183</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the codes contain 26 or TC but have extra characters you may be looking for&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if index(mod_1,'26')&amp;gt;0 then ...&lt;/P&gt;&lt;P&gt;instead of equals.&lt;/P&gt;&lt;P&gt;Especially if the mod_1 code looks like "000abc26-XYZ". In which case "=" is definitely not what you want.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jul 2012 22:50:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-if-then-with-characters-in-SAS/m-p/117837#M293183</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2012-07-25T22:50:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to use if-then with characters in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-if-then-with-characters-in-SAS/m-p/117838#M293184</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To know if the variables contains trailing blanks try this...(borrowed from Tom's code) then you can change your if conditions accordingly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;ss='&amp;nbsp; 05';output;&lt;/P&gt;&lt;P&gt;ss=' 09';output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt; data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; put (_character_) (= $quote. );&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Shiva&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jul 2012 09:09:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-if-then-with-characters-in-SAS/m-p/117838#M293184</guid>
      <dc:creator>shivas</dc:creator>
      <dc:date>2012-07-26T09:09:06Z</dc:date>
    </item>
  </channel>
</rss>

