<?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 Why the command statement didn't work? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846676#M334685</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I would like to put the value either in "Pro" column or "Tec" column into a new column "Total_cost".&amp;nbsp; The new column results are all missing, how come?&amp;nbsp; All of the columns are numeric, please help.&amp;nbsp; Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	Format Total_Cost DOLLAR10.2;
        if class=9 then Total_cost=Pro;
	else if class in (1,2,3,4,5,6,7,8,10) then Total_Cost=Tec;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 28 Nov 2022 19:26:02 GMT</pubDate>
    <dc:creator>ybz12003</dc:creator>
    <dc:date>2022-11-28T19:26:02Z</dc:date>
    <item>
      <title>Why the command statement didn't work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846676#M334685</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I would like to put the value either in "Pro" column or "Tec" column into a new column "Total_cost".&amp;nbsp; The new column results are all missing, how come?&amp;nbsp; All of the columns are numeric, please help.&amp;nbsp; Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	Format Total_Cost DOLLAR10.2;
        if class=9 then Total_cost=Pro;
	else if class in (1,2,3,4,5,6,7,8,10) then Total_Cost=Tec;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Nov 2022 19:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846676#M334685</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2022-11-28T19:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: Why the command statement didn't work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846678#M334686</link>
      <description>&lt;P&gt;Look at your data to tell the answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are the actual values of CLASS?&amp;nbsp; If the value is not an integer from 1 to 10 then you never assign any value to TOTAL_COST.&lt;/P&gt;
&lt;P&gt;What are the values of TEC and PRO?&amp;nbsp; Do any of the observations have missing values?&amp;nbsp; Any missing values that are selected by the IF/THEN/ELSE block will be propagated into TOTAL_COST.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2022 19:36:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846678#M334686</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-28T19:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: Why the command statement didn't work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846684#M334687</link>
      <description>Class is from 1 to 10.&lt;BR /&gt;Both TEC and PRO carry missing values.  The sample values are shown below.&lt;BR /&gt;644.95&lt;BR /&gt;35130.1&lt;BR /&gt;8.02&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 28 Nov 2022 20:29:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846684#M334687</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2022-11-28T20:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: Why the command statement didn't work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846687#M334688</link>
      <description>&lt;P&gt;Please post the log of your program. If TEC and PRO only contain missing values then your program isn't going to work as you wanted.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2022 20:46:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846687#M334688</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-11-28T20:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: Why the command statement didn't work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846692#M334691</link>
      <description>&lt;P&gt;It's possible the values of class have unexpected values (maybe they are not actually integers).&amp;nbsp; When you have an IF/ELSE IF block that you expect to be exhaustive, it's often helpful to add an ELSE statement that will write an error message to the log if any values do not fall into one of the expected bins, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	Format Total_Cost DOLLAR10.2;
	if class=9 then Total_cost=Pro;
	else if class in (1,2,3,4,5,6,7,8,10) then Total_Cost=Tec;
	else put "ERROR: unexpected value " class= ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that code runs without errors, then I would check the values of PRO and TEC to make sure they are not null.&amp;nbsp; You can also add an assertion to your code to check this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	Format Total_Cost DOLLAR10.2;
	if NOT (Pro &amp;gt;=0 ) then put "ERROR: " Pro= ;
	if NOT (Tec &amp;gt;=0 ) then put "ERROR: " Tec= ;
	if class=9 then Total_cost=Pro;
	else if class in (1,2,3,4,5,6,7,8,10) then Total_Cost=Tec;
	else put "ERROR: unexpected value " class= ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It also helps to check values by writing them to the log, with PUT statements, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	Format Total_Cost DOLLAR10.2;
	if NOT (Pro &amp;gt;=0 ) then put "ERROR: " Pro= ;
	if NOT (Tec &amp;gt;=0 ) then put "ERROR: " Tec= ;
	if class=9 then Total_cost=Pro;
	else if class in (1,2,3,4,5,6,7,8,10) then Total_Cost=Tec;
	else put "ERROR: unexpected value " class= ;
	put (Class Pro Tec Total_Cost)(=) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you run that last step, the log should make clear what is happening.&amp;nbsp; If the log doesn't make sense to you, please post the log you get.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2022 20:59:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846692#M334691</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-11-28T20:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: Why the command statement didn't work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846718#M334706</link>
      <description>You are right; most of the values are not integers.  I used your code to run my dataset, and tons of Error messages were shown in the log window.  Below is some examples.&lt;BR /&gt;&lt;BR /&gt;ERROR: Pro=.&lt;BR /&gt;ERROR: unexpected value class=9&lt;BR /&gt;class=9 Pro=. Tec=35130.1 Total_Cost=.&lt;BR /&gt;&lt;BR /&gt;ERROR: Pro=.&lt;BR /&gt;class=5 Pro=. Tec=445.49 Total_Cost=445.49&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 29 Nov 2022 01:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846718#M334706</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2022-11-29T01:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: Why the command statement didn't work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846724#M334711</link>
      <description>&lt;P&gt;Posting error messages without the code that is generating them isn't useful. Please post your COMPLETE SAS log including code, notes and errors.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 02:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846724#M334711</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-11-29T02:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: Why the command statement didn't work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846726#M334712</link>
      <description>Please try the following:&lt;BR /&gt;1. Comment out the format statement - does anything show up in total cost?&lt;BR /&gt;2. Run proc freq on class variable - are values there?&lt;BR /&gt;</description>
      <pubDate>Tue, 29 Nov 2022 02:55:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846726#M334712</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2022-11-29T02:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: Why the command statement didn't work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846727#M334713</link>
      <description>1. Nothing is shown in the Total cost.&lt;BR /&gt;2. Frequency counts are shown in the Proc freq class table.</description>
      <pubDate>Tue, 29 Nov 2022 03:06:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846727#M334713</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2022-11-29T03:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: Why the command statement didn't work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846732#M334718</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;You are right; most of the values are not integers. I used your code to run my dataset, and tons of Error messages were shown in the log window. Below is some examples.&lt;BR /&gt;&lt;BR /&gt;ERROR: Pro=.&lt;BR /&gt;ERROR: unexpected value class=9&lt;BR /&gt;class=9 Pro=. Tec=35130.1 Total_Cost=.&lt;BR /&gt;&lt;BR /&gt;ERROR: Pro=.&lt;BR /&gt;class=5 Pro=. Tec=445.49 Total_Cost=445.49&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;IF you ran the code suggested (hard to tell since you did not show the full log) then the second ERROR line you show means that the value of CLASS that is printing as 9 is not actually 9.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does it have any format permanently attached?&amp;nbsp; &amp;nbsp;What format?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is character you should have gotten messages in the log about converting characters to numbers.&amp;nbsp; Like this:&lt;/P&gt;
&lt;PRE&gt;1956  data test;
1957    class='9';
1958    if class in (9) then put 'equal 9';
1959  run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      1958:6
equal 9
&lt;/PRE&gt;
&lt;P&gt;In which case the only reason it would print like 9 but not equal 9 would be if it had some non-printing character, like a TAB or CARRIAGE RETURN character in it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is numeric and has no format attached SAS will use the BEST12. format to display the value in that PUT statement.&amp;nbsp; In which case it is very close to 9.&amp;nbsp; You could try converting the CLASS to an integer using the INT() function.&amp;nbsp; Or perhaps just round it case there might be decimal places you want to keep.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 04:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846732#M334718</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-29T04:19:46Z</dc:date>
    </item>
  </channel>
</rss>

