<?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 properly write out string in a if statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-properly-write-out-string-in-a-if-statement/m-p/597355#M172105</link>
    <description>&lt;P&gt;Hi Y'all!&lt;/P&gt;
&lt;P&gt;will work very well &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Oct 2019 14:50:27 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-10-17T14:50:27Z</dc:date>
    <item>
      <title>How to properly write out string in a if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-properly-write-out-string-in-a-if-statement/m-p/597158#M172036</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to use an if statement to create a new column variable in my datasets:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*I imported the csv file so the input here is just for demonstration;&lt;/P&gt;&lt;P&gt;input RoundNo;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;10&lt;/P&gt;&lt;P&gt;11&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if RoundNo &amp;lt;= 9 then round_cat = "early";&lt;BR /&gt;else&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;round_cat = "late_stage";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I check my output, instead of "late_stage", I only got "late_" so I am confused about what happened here. Can someone help me with this ? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 19:29:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-properly-write-out-string-in-a-if-statement/m-p/597158#M172036</guid>
      <dc:creator>raselle</dc:creator>
      <dc:date>2019-10-17T19:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly write out string in a if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-properly-write-out-string-in-a-if-statement/m-p/597166#M172041</link>
      <description>&lt;P&gt;Welcome to SAS Community.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
set have;
       if RoundNo &amp;lt;= 9 then round_cat = "early";
else
       round_cat = "late_stage";
run;&lt;/PRE&gt;
&lt;P&gt;The length of ROUND_CAT is assumed to be the length of EARLY as it occurs first. Since LATE_STAGE is longer than EARLY, ROUND_CAT holds the length of EARLY- that is 5 characters from LATE_STAGE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use:&lt;/P&gt;
&lt;P&gt;Length ROUND_CAT $ 10&lt;/P&gt;
&lt;P&gt;to hold both the labels&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 04:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-properly-write-out-string-in-a-if-statement/m-p/597166#M172041</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-10-17T04:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly write out string in a if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-properly-write-out-string-in-a-if-statement/m-p/597172#M172045</link>
      <description>&lt;P&gt;That worked perfectly! Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 05:04:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-properly-write-out-string-in-a-if-statement/m-p/597172#M172045</guid>
      <dc:creator>raselle</dc:creator>
      <dc:date>2019-10-17T05:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly write out string in a if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-properly-write-out-string-in-a-if-statement/m-p/597183#M172053</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295550"&gt;@raselle&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi guys,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note that we're mixed gender here, and that the most prolific solution provider is not a "guy", so she has made it a point to never answer questions that begin like that.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 05:53:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-properly-write-out-string-in-a-if-statement/m-p/597183#M172053</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-17T05:53:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly write out string in a if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-properly-write-out-string-in-a-if-statement/m-p/597349#M172103</link>
      <description>&lt;P&gt;I'm a non-native speaker and thought that "guys" is a gender-neutral words. I will keep that in mind next time. Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 14:43:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-properly-write-out-string-in-a-if-statement/m-p/597349#M172103</guid>
      <dc:creator>raselle</dc:creator>
      <dc:date>2019-10-17T14:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly write out string in a if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-properly-write-out-string-in-a-if-statement/m-p/597355#M172105</link>
      <description>&lt;P&gt;Hi Y'all!&lt;/P&gt;
&lt;P&gt;will work very well &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 14:50:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-properly-write-out-string-in-a-if-statement/m-p/597355#M172105</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-17T14:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly write out string in a if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-properly-write-out-string-in-a-if-statement/m-p/597374#M172108</link>
      <description>&lt;P&gt;I will use that from now then.&amp;nbsp;&lt;img id="smileyvery-happy" class="emoticon emoticon-smileyvery-happy" src="https://communities.sas.com/i/smilies/16x16_smiley-very-happy.png" alt="Smiley Very Happy" title="Smiley Very Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 14:57:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-properly-write-out-string-in-a-if-statement/m-p/597374#M172108</guid>
      <dc:creator>raselle</dc:creator>
      <dc:date>2019-10-17T14:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly write out string in a if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-properly-write-out-string-in-a-if-statement/m-p/597397#M172124</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295550"&gt;@raselle&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi guys,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to use an if statement to create a new column variable in my datasets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*I imported the csv file so the input here is just for demonstration;&lt;/P&gt;
&lt;P&gt;input RoundNo;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;10&lt;/P&gt;
&lt;P&gt;11&lt;/P&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if RoundNo &amp;lt;= 9 then round_cat = "early";&lt;BR /&gt;else&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;round_cat = "late_stage";&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I check my output, instead of "late_stage", I only got "late_" so I am confused about what happened here. Can someone help me with this ? Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Many times you can avoid creating new variables if the value you need is based on single variable by creating a custom format and using that as needed. The following code creates an example data set of values and two custom formats. Then uses proc print to display the same variable with the two formats applied.&lt;/P&gt;
&lt;PRE&gt;data work.example;
   do x= 1 to 15;
   output;
   end;
run;

proc format library=work;
value early
low - 9 = "Early"
other = "Late stage"
;
value olevels
0 - 3 = '[0,3]'
3&amp;lt;- 6 = '(3,6]'
6&amp;lt;- high='&amp;gt;6'
;
run;

Title "X with format Early";
proc print data=work.example;
   var x;
   format x early.;
run;
Title "X with format Olevels";
proc print data=work.example;
   var x;
   format x olevels.;
run;title;&lt;/PRE&gt;
&lt;P&gt;Formats like this are honored for most analysis, graphing or reporting procedures to not only display values but create groups for analysis or display.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also for some sorts of code with lots of ranges the code in Proc Format can be much easier to write/maintain then a bunch of "if then else" statements. Once you have a format created you can apply it to many variables that might want similar behavior. Imagine if you have many RoundNo type variables. You want have to create a separate text variable for each group, keep the names and possibly labels&amp;nbsp;straight and other fiddly bits. With the format it is just change the format statement and go.&lt;/P&gt;
&lt;P&gt;Formats also work with character variables though attempting to use ranges of values is usually very problematic. Imagine that&amp;nbsp; you have a list of Office names that you want to treat as a group for some purposes such as a management region. Instead of coding a bunch of if/then/else statements a format works just fine. And when a new office is opened you just add it to the format. Not other code needs to change. Or if an office changes management region change the format to show that change. Of if the office closes you can have a value of the format that points to "closed branches".&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 15:43:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-properly-write-out-string-in-a-if-statement/m-p/597397#M172124</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-17T15:43:29Z</dc:date>
    </item>
  </channel>
</rss>

