<?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 &amp;quot;PUT&amp;quot; function and Formats in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-and-Formats/m-p/59846#M12960</link>
    <description>I have a variable of diagnosis codes called "Diag" it has different values ranging from 2 digits to 5 digits  ( e.g.  72,  359,  3388,  23995).  I am defining a CC and I was changing DIAG to a "character value" as in the following statement :&lt;BR /&gt;
CC = LEFT(PUT(put(DIAG,5.),$I&amp;amp;VR.C.)); &lt;BR /&gt;
&lt;BR /&gt;
The problem from the output is that it recognizes "Diag" with 5 digits only. I want it to do the same with other "Diag " codes. What could I do to make sure it recognizes each of the codes whether they have 2, 3, 4 or 5 digits?</description>
    <pubDate>Wed, 05 Nov 2008 22:00:46 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-11-05T22:00:46Z</dc:date>
    <item>
      <title>"PUT" function and Formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-and-Formats/m-p/59846#M12960</link>
      <description>I have a variable of diagnosis codes called "Diag" it has different values ranging from 2 digits to 5 digits  ( e.g.  72,  359,  3388,  23995).  I am defining a CC and I was changing DIAG to a "character value" as in the following statement :&lt;BR /&gt;
CC = LEFT(PUT(put(DIAG,5.),$I&amp;amp;VR.C.)); &lt;BR /&gt;
&lt;BR /&gt;
The problem from the output is that it recognizes "Diag" with 5 digits only. I want it to do the same with other "Diag " codes. What could I do to make sure it recognizes each of the codes whether they have 2, 3, 4 or 5 digits?</description>
      <pubDate>Wed, 05 Nov 2008 22:00:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-and-Formats/m-p/59846#M12960</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-11-05T22:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: "PUT" function and Formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-and-Formats/m-p/59847#M12961</link>
      <description>Hi:&lt;BR /&gt;
  SAS functions resolve from the innermost function call to the outermost function call. So your LEFT function isn't being applied &lt;BR /&gt;
until after the PUT using $DIAG.&lt;BR /&gt;
 &lt;BR /&gt;
  You have a couple of choices as shown in the progam below. If DIAG is a numeric variable, then you could just &lt;BR /&gt;
make a numeric format for diagnosis codes and that would simplify everything (see NDIAG format and the CC_FROM_NUM &lt;BR /&gt;
variable in the output.&lt;BR /&gt;
&lt;BR /&gt;
  Putting the LEFT in a different position works (CC_LEFT variable) also, using STRIP, COMPRESS or SCAN &lt;BR /&gt;
functions return the desired results. However, the TRIM function does NOT work, because you need to remove ALL &lt;BR /&gt;
blanks or have all blanks disregarded, not just the trailing blanks.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
The program:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data diagcode;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input name $ diag;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
Alan 72&lt;BR /&gt;
Bob 359&lt;BR /&gt;
Carla 3388&lt;BR /&gt;
Dana 23995&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
            &lt;BR /&gt;
proc format;&lt;BR /&gt;
  value $diag '72'='Tennis Elbow'&lt;BR /&gt;
              '359' = 'Migraine'&lt;BR /&gt;
              '3388' = 'Imaginary Voices'&lt;BR /&gt;
              '23995' = 'Text Messaging Thumb';&lt;BR /&gt;
              &lt;BR /&gt;
  value ndiag 72 = 'Tennis Elbow'&lt;BR /&gt;
              359 = 'Migraine'&lt;BR /&gt;
              3388 = 'Imaginary Voices'&lt;BR /&gt;
              23995 = 'Text Messaging Thumb';&lt;BR /&gt;
         &lt;BR /&gt;
run;&lt;BR /&gt;
options nodate nonumber nocenter;&lt;BR /&gt;
title 'Use Diag Format';&lt;BR /&gt;
data putdiag;&lt;BR /&gt;
  set diagcode;&lt;BR /&gt;
               &lt;BR /&gt;
  cc_orig= LEFT(PUT(put(DIAG,5.),$diag.)); &lt;BR /&gt;
  ** break your original creation into 3 steps;&lt;BR /&gt;
  ** you can see that the 2nd PUT of the character value;&lt;BR /&gt;
  ** does NOT result in the desired code because;&lt;BR /&gt;
  ** the numbers are still right justified when the;&lt;BR /&gt;
  ** second PUT is performed. The LEFT function does not;&lt;BR /&gt;
  ** have an effect after the second PUT.;&lt;BR /&gt;
  orig_1=put(DIAG,5.);&lt;BR /&gt;
  orig_2 = PUT(orig_1,$diag.);&lt;BR /&gt;
  orig_3 = left(orig_2);&lt;BR /&gt;
              &lt;BR /&gt;
  * use a numeric format instead of a character format;&lt;BR /&gt;
  cc_from_num = put(diag,ndiag.);&lt;BR /&gt;
         &lt;BR /&gt;
  ** if you do use a character format, make sure to use;&lt;BR /&gt;
  ** functions that result in your "trailing" spaces being ;&lt;BR /&gt;
  ** ignored or disregarded for the put of $DIAG.;&lt;BR /&gt;
  ** note how the LEFT function is used AFTER the first put;&lt;BR /&gt;
  ** and BEFORE the second PUT (nested functions resolve from the inside out);&lt;BR /&gt;
  cc_left = put(left(put(diag,8.)),$diag.);&lt;BR /&gt;
  cc_str = put(strip(put(diag,8.)),$diag.);&lt;BR /&gt;
  cc_comp = put(compress(put(diag,8.)),$diag.);&lt;BR /&gt;
  cc_scan = put(scan(put(diag,8.),1),$diag.);&lt;BR /&gt;
              &lt;BR /&gt;
  ** trim does not produce the desired results;&lt;BR /&gt;
  cc_trim = put(trim(put(diag,8.)),$diag.);&lt;BR /&gt;
      &lt;BR /&gt;
run;&lt;BR /&gt;
       &lt;BR /&gt;
options linesize=200;&lt;BR /&gt;
proc print data=putdiag;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
The output:&lt;BR /&gt;
[pre]&lt;BR /&gt;
Use Diag Format&lt;BR /&gt;
                                      &lt;BR /&gt;
Obs name   diag cc_orig              orig_1 orig_2               orig_3               cc_from_num          cc_left              cc_str               cc_comp              cc_scan              cc_trim&lt;BR /&gt;
&lt;BR /&gt;
 1  Alan     72 72                      72     72                72                   Tennis Elbow         Tennis Elbow         Tennis Elbow         Tennis Elbow         Tennis Elbow             72&lt;BR /&gt;
 2  Bob     359 359                    359    359                359                  Migraine             Migraine             Migraine             Migraine             Migraine                359&lt;BR /&gt;
 3  Carla  3388 3388                  3388   3388                3388                 Imaginary Voices     Imaginary Voices     Imaginary Voices     Imaginary Voices     Imaginary Voices       3388&lt;BR /&gt;
 4  Dana  23995 Text Messaging Thumb 23995  Text Messaging Thumb Text Messaging Thumb Text Messaging Thumb Text Messaging Thumb Text Messaging Thumb Text Messaging Thumb Text Messaging Thumb  23995&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 05 Nov 2008 22:51:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-and-Formats/m-p/59847#M12961</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-11-05T22:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: "PUT" function and Formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-and-Formats/m-p/59848#M12962</link>
      <description>Hi Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
You made my day.  It worked perfectly.  Thank you very much.&lt;BR /&gt;
&lt;BR /&gt;
Liv</description>
      <pubDate>Thu, 06 Nov 2008 15:38:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-and-Formats/m-p/59848#M12962</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-11-06T15:38:25Z</dc:date>
    </item>
  </channel>
</rss>

