<?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: Length Statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835071#M330112</link>
    <description>Thank you! I was looking for help to identify the issue with the length statement in my code.</description>
    <pubDate>Sun, 25 Sep 2022 18:14:10 GMT</pubDate>
    <dc:creator>Naive_help</dc:creator>
    <dc:date>2022-09-25T18:14:10Z</dc:date>
    <item>
      <title>Length Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835046#M330097</link>
      <description>&lt;P&gt;Used current SAS studio to execute the following program.&lt;/P&gt;&lt;P&gt;Length statement was applied to set the length (17) to "Smoking_Status" in the "if statement" below&lt;/P&gt;&lt;P&gt;However, still, the values for "Smoking_Status" are truncated (see below in the table attributes).&lt;/P&gt;&lt;P&gt;I would appreciate it if you could help me figure this out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Sep 2022 12:14:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835046#M330097</guid>
      <dc:creator>Naive_help</dc:creator>
      <dc:date>2022-09-25T12:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: Length Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835047#M330098</link>
      <description>&lt;P&gt;LENGTH statements cannot be part of an IF statement. LENGTH statements cannot be executed conditionally. It applies to all observations of a variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We can't see your code, you did not include it in your message. (Do not attach files, include your code in your reply as text) If we could see your code, we could suggest other ways to do this.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Sep 2022 12:20:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835047#M330098</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-25T12:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: Length Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835064#M330106</link>
      <description>Here is the code -&lt;BR /&gt;&lt;BR /&gt;data heart1 (drop=AgeatDeath Deathcause);&lt;BR /&gt;length Smoking_Status $ 17;&lt;BR /&gt;set heart;&lt;BR /&gt;where status = "Alive";&lt;BR /&gt;if AgeCHDdiag=. then delete;&lt;BR /&gt;If 0 =&amp;lt; smoking &amp;lt;= 6 then Smoking_Statuser = "None (0–5)";&lt;BR /&gt;else If 6 =&amp;lt; smoking &amp;lt;= 15 then Smoking_Statuser = "Moderate (6–15)";&lt;BR /&gt;else If 16 =&amp;lt; smoking &amp;lt;= 25 then Smoking_Statuser = "Heavy (16–25)";&lt;BR /&gt;else If smoking gt 25 then Smoking_Statuser = "Very Heavy (&amp;gt;25)";&lt;BR /&gt;else Smoking_Statuser = "Error";&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Sun, 25 Sep 2022 16:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835064#M330106</guid>
      <dc:creator>Naive_help</dc:creator>
      <dc:date>2022-09-25T16:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: Length Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835065#M330107</link>
      <description>&lt;P&gt;The code is using a different variable name in the LENGTH statement than the one used in the series of IF/THEN/ELSE statements.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Sep 2022 16:18:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835065#M330107</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-25T16:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: Length Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835067#M330109</link>
      <description>Thank you!&lt;BR /&gt;Made changes to code. I still see that length statement is not applied.&lt;BR /&gt;&lt;BR /&gt;data heart1 (drop=AgeatDeath Deathcause);&lt;BR /&gt;length Smoking_Status $ 17;&lt;BR /&gt;set heart;&lt;BR /&gt;where status = "Alive";&lt;BR /&gt;if AgeCHDdiag=. then delete;&lt;BR /&gt;If 0 =&amp;lt; smoking &amp;lt;= 6 then Smoking_Status= "None (0–5)";&lt;BR /&gt;else If 6 =&amp;lt; smoking &amp;lt;= 15 then Smoking_Status = "Moderate (6–15)";&lt;BR /&gt;else If 16 =&amp;lt; smoking &amp;lt;= 25 then Smoking_Status = "Heavy (16–25)";&lt;BR /&gt;else If smoking gt 25 then Smoking_Status = "Very Heavy (&amp;gt;25)";&lt;BR /&gt;else Smoking_Statuser = "Error";&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Sun, 25 Sep 2022 17:08:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835067#M330109</guid>
      <dc:creator>Naive_help</dc:creator>
      <dc:date>2022-09-25T17:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: Length Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835069#M330111</link>
      <description>&lt;P&gt;You have overlapping ranges.&amp;nbsp; BTW you don't need to create the Smoking_Status variable.&amp;nbsp; Just use Proc format to display the label.&amp;nbsp; In case you do want to create the Smoking_Status variable use the put function&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc format;
  value statfmt (multilabel) 
	0–5= "None (0–5)"
    6–15 = "Moderate (6–15)"
    16–25 = "Heavy (16–25)"
	26-high	= "Very Heavy (&amp;gt;25)"
	other = "Error";
run;
data heart1 (drop=AgeatDeath Deathcause);
	length Smoking_Status $ 17;
	set heart;
	where status = "Alive";
	if AgeCHDdiag is missing then delete;
    format smoking statfmt.;
/* optional: to create the Smoking_Status var */
    Smoking_Status=put(Smoking_Status,statfmt.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Sep 2022 20:05:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835069#M330111</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2022-09-25T20:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: Length Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835071#M330112</link>
      <description>Thank you! I was looking for help to identify the issue with the length statement in my code.</description>
      <pubDate>Sun, 25 Sep 2022 18:14:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835071#M330112</guid>
      <dc:creator>Naive_help</dc:creator>
      <dc:date>2022-09-25T18:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: Length Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835072#M330113</link>
      <description>Well, you should show them log as well as proc content listing off your dataset.&lt;BR /&gt;&lt;BR /&gt;You haven't provided any details for us to give you any meaningful answer</description>
      <pubDate>Sun, 25 Sep 2022 19:12:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835072#M330113</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2022-09-25T19:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: Length Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835074#M330114</link>
      <description>&lt;P&gt;You missed one misspelling.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are still seeing "truncation" then perhaps SMOKING_STATUS was already in the source dataset, HEART, and for someone accidentally attached a format to the variable that displays fewer than all 17 bytes of the value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could try removing any format that might have been attached to the variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data heart1; 
  length Smoking_Status $17;
  set heart;
  where status = "Alive" and not missing(AgeCHDdiag);
&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;  format Smoking_Status ;&lt;/STRONG&gt;&lt;/FONT&gt;
  if smoking &amp;lt; 0 then Smoking_Status = "Error";
  else if smoking &amp;lt;= 5 then Smoking_Status= "None (0–5)";
  else If smoking &amp;lt;= 15 then Smoking_Status = "Moderate (6–15)";
  else If smoking &amp;lt;= 25 then Smoking_Status = "Heavy (16–25)";
  else  Smoking_Status = "Very Heavy (&amp;gt;25)";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Sep 2022 19:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835074#M330114</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-25T19:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Length Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835077#M330116</link>
      <description>Excellent! Very insightful. Yes! Someone already had attached the format.</description>
      <pubDate>Sun, 25 Sep 2022 19:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835077#M330116</guid>
      <dc:creator>Naive_help</dc:creator>
      <dc:date>2022-09-25T19:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: Length Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835080#M330119</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/433457"&gt;@Naive_help&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use custom formats instead of character strings and this avoids the entire LENGTH issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
    value smokef
        low-&amp;lt;0="Error"
        0-5="None (0-5)"
        6-15="Moderate (6-15)"
        16-25="Heavy (16-25)"
        26-high="Very Heavy (&amp;gt;25)";
run;
data heart1;  /* Or better yet, use PROC DATASETS to change a format */
    set heart;
    format smoking smokef.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Custom formats have another benefit ... the variable smoking remains numeric, and can be sorted NUMERICALLY. Your character variable&amp;nbsp; SMOKING_STATUS will sort alphabetically, this is not what you want, and so any reports or tables created with a SMOKING_STATUS will look out-of-order.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Sep 2022 20:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-Statement/m-p/835080#M330119</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-25T20:41:24Z</dc:date>
    </item>
  </channel>
</rss>

