<?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: Proc SQL: Case Expression. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Case-Expression/m-p/34434#M8395</link>
    <description>Hi. After Flip's  suggestion.&lt;BR /&gt;
your sql statement&lt;BR /&gt;
&lt;BR /&gt;
 " case value_held&lt;BR /&gt;
when value_held = . then value_held = price * shr_held&lt;BR /&gt;
else value_held = value_held&lt;BR /&gt;
end as value_held,&lt;BR /&gt;
price "&lt;BR /&gt;
&lt;BR /&gt;
Should be &lt;BR /&gt;
&lt;BR /&gt;
"price,case value_held&lt;BR /&gt;
when value_held = . then value_held = price * shr_held&lt;BR /&gt;
else value_held = value_held&lt;BR /&gt;
end as value_held"&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Because the calculated column should be behind the column used to calculate.&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
    <pubDate>Sat, 12 Jun 2010 07:14:35 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2010-06-12T07:14:35Z</dc:date>
    <item>
      <title>Proc SQL: Case Expression.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Case-Expression/m-p/34431#M8392</link>
      <description>I have a data set which includes a variable called "value_held". This variable is numeric and it contains both missing and non-missing values. For non-missing values, I'd like to replace them with an expression which is (price * shr_held), i.e. price * # shares held.&lt;BR /&gt;
&lt;BR /&gt;
To my surprise, after running the SQL queries, all observations of value_held equal 1. How come? I've read the SAS 9.1 SQL Users Guide, but still have no clue. Everything is equal to 1 for all observations of value_held!!! Can you please help? Thanks a lot.&lt;BR /&gt;
&lt;BR /&gt;
Here is my SQL program:&lt;BR /&gt;
&lt;BR /&gt;
/* Merge MF holdings with stock prices */&lt;BR /&gt;
proc sql feedback inobs=100000;&lt;BR /&gt;
	create table luong.mf_holdings as&lt;BR /&gt;
		select 	owner_id, fund_country_id, fund_country_name,&lt;BR /&gt;
					year, coalesce(f.rep_date, p.price_date) as rep_date format=ddmmyy10.,&lt;BR /&gt;
					coalesce(f.security_id, p.security_id) as security_id, &lt;BR /&gt;
					cusip, sedol, isin, ticker_sym,&lt;BR /&gt;
					firm_country_id, firm_country_name,&lt;BR /&gt;
					shr_held, &lt;BR /&gt;
					case value_held&lt;BR /&gt;
						when value_held = . then value_held = price * shr_held&lt;BR /&gt;
						else value_held = value_held&lt;BR /&gt;
					end as value_held,&lt;BR /&gt;
					price&lt;BR /&gt;
			from mf_holdings2 as f, price.price_hist_all as p&lt;BR /&gt;
			where f.security_id = p.security_id &lt;BR /&gt;
				and f.rep_date = p.price_date&lt;BR /&gt;
			order by owner_id, security_id, firm_country_id;&lt;BR /&gt;
quit;&lt;B&gt;&lt;/B&gt;&lt;B&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt;&lt;B&gt;&lt;/B&gt;&lt;B&gt;&lt;/B&gt;

Message was edited by: hoangluong</description>
      <pubDate>Fri, 11 Jun 2010 06:27:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Case-Expression/m-p/34431#M8392</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-06-11T06:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL: Case Expression.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Case-Expression/m-p/34432#M8393</link>
      <description>For starters, your description doesn't match you program logic. My guess is that your program has the correct logic.&lt;BR /&gt;
It would be easier to help if you could attach some sample data.&lt;BR /&gt;
/Linus</description>
      <pubDate>Fri, 11 Jun 2010 08:07:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Case-Expression/m-p/34432#M8393</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2010-06-11T08:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL: Case Expression.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Case-Expression/m-p/34433#M8394</link>
      <description>You are mixing 2 forms of the CASE opperator.&lt;BR /&gt;
use &lt;BR /&gt;
case &lt;BR /&gt;
when value_held = . then value_held = price * shr_held&lt;BR /&gt;
else  value_held&lt;BR /&gt;
end as value_held,&lt;BR /&gt;
&lt;BR /&gt;
OR&lt;BR /&gt;
&lt;BR /&gt;
case value_held&lt;BR /&gt;
when  . then price * shr_held&lt;BR /&gt;
else  value_held&lt;BR /&gt;
end as value_held,&lt;BR /&gt;
&lt;BR /&gt;
Or just use COALESCE(value_held, price*shr_held);</description>
      <pubDate>Fri, 11 Jun 2010 11:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Case-Expression/m-p/34433#M8394</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2010-06-11T11:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL: Case Expression.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Case-Expression/m-p/34434#M8395</link>
      <description>Hi. After Flip's  suggestion.&lt;BR /&gt;
your sql statement&lt;BR /&gt;
&lt;BR /&gt;
 " case value_held&lt;BR /&gt;
when value_held = . then value_held = price * shr_held&lt;BR /&gt;
else value_held = value_held&lt;BR /&gt;
end as value_held,&lt;BR /&gt;
price "&lt;BR /&gt;
&lt;BR /&gt;
Should be &lt;BR /&gt;
&lt;BR /&gt;
"price,case value_held&lt;BR /&gt;
when value_held = . then value_held = price * shr_held&lt;BR /&gt;
else value_held = value_held&lt;BR /&gt;
end as value_held"&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Because the calculated column should be behind the column used to calculate.&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Sat, 12 Jun 2010 07:14:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Case-Expression/m-p/34434#M8395</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-06-12T07:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL: Case Expression.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Case-Expression/m-p/34435#M8396</link>
      <description>Thank you all for the help!</description>
      <pubDate>Thu, 17 Jun 2010 04:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Case-Expression/m-p/34435#M8396</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-06-17T04:59:17Z</dc:date>
    </item>
  </channel>
</rss>

