<?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 a proc sql and a case statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751369#M236521</link>
    <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;I came to write a case statement in a proc sql, I get error 22-322 expecting a name.&lt;/P&gt;
&lt;PRE&gt;proc sql;
 create table mytable as
select distict b.*,
case
when b.rate &amp;lt; 35 then 'do this'
when b.rate &amp;lt; 50 then 'do that'
else 'Error'
end as 'this is final rate', a.plan, a.diagcode
from tableb  b left outer join tablea a on b.plan=a.plan;
quit;&lt;/PRE&gt;
&lt;P&gt;Any help?&lt;/P&gt;
&lt;P&gt;I get error on this part:&amp;nbsp;'this is final rate'&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Blue Blue&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Jun 2021 23:17:38 GMT</pubDate>
    <dc:creator>GN0001</dc:creator>
    <dc:date>2021-06-30T23:17:38Z</dc:date>
    <item>
      <title>a proc sql and a case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751369#M236521</link>
      <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;I came to write a case statement in a proc sql, I get error 22-322 expecting a name.&lt;/P&gt;
&lt;PRE&gt;proc sql;
 create table mytable as
select distict b.*,
case
when b.rate &amp;lt; 35 then 'do this'
when b.rate &amp;lt; 50 then 'do that'
else 'Error'
end as 'this is final rate', a.plan, a.diagcode
from tableb  b left outer join tablea a on b.plan=a.plan;
quit;&lt;/PRE&gt;
&lt;P&gt;Any help?&lt;/P&gt;
&lt;P&gt;I get error on this part:&amp;nbsp;'this is final rate'&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Blue Blue&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 23:17:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751369#M236521</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-06-30T23:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: a proc sql and a case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751370#M236522</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;I came to write a case statement in a proc sql, I get error 22-322 expecting a name.&lt;/P&gt;
&lt;PRE&gt;proc sql;
 create table mytable as
select distict b.*,
case
when b.rate &amp;lt; 35 then 'do this'
when b.rate &amp;lt; 50 then 'do that'
else 'Error'
end as &lt;FONT size="6" color="#FF0000"&gt;&lt;STRONG&gt;'this is final rate'&lt;/STRONG&gt;&lt;/FONT&gt;, a.plan, a.diagcode
from tableb  b left outer join tablea a on b.plan=a.plan;
quit;&lt;/PRE&gt;
&lt;P&gt;Any help?&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Blue Blue&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Highlighted text is not a valid SAS variable name. If you insist on using non-standard named variables then the name must be in quotes and followed with an N to indicate that it is a&amp;nbsp; name literal. "Nonstandard name"n for example.&lt;/P&gt;
&lt;P&gt;And you will have to have the SAS system option of Validvarname=any; set as well.&lt;/P&gt;
&lt;P&gt;What is lost by using a name like This_is_final_rate? If you want other text to appear then use a LABEL for the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc sql;
   create table junk as
   select *,
      case 
         when sex= 'F' then 'something'
         when sex= 'M' then 'something else'
         else 'Error'
      end as newvar label='This is a Sex based value'
   from sashelp.class
   ;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Jun 2021 23:22:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751370#M236522</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-30T23:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: a proc sql and a case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751371#M236523</link>
      <description>&lt;P&gt;This is a syntax error because "this is final rate" is a string, not a variable name. You can tell SAS to consider that name as a variable name by adding the suffix n&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;.... end as "this is final rate"n, ...&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 23:22:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751371#M236523</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-06-30T23:22:26Z</dc:date>
    </item>
    <item>
      <title>Re: a proc sql and a case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751375#M236525</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Highlighted text is not a valid SAS variable name. If you insist on using non-standard named variables then the name must be in quotes and followed with an N to indicate that it is a&amp;nbsp; name literal. "Nonstandard name"n for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where should I add&amp;nbsp;system option of Validvarname=any; ? Wherever, I ues Validvarname, it says: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is lost by using a name like This_is_final_rate? If you want other text to appear then use a LABEL for the variable.&lt;/P&gt;
&lt;P&gt;Label is ignored and newVar appears as the header for the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any other suggestion? What did I do wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for all,&lt;/P&gt;
&lt;P&gt;Blue Blue&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 00:15:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751375#M236525</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-07-01T00:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: a proc sql and a case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751376#M236526</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;When I add: "This is final total"n, I have to set&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;Validvarname=any;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;without validvarname, it says too long for a sas name in this context.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;with validvarname, error is: statement is not valid or it is used out of proper order.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;with newvar label='This is final total, newvar is being show as the header for variable in the dataset.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;blue blue&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 00:20:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751376#M236526</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-07-01T00:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: a proc sql and a case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751378#M236528</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;When I add: "This is final total"n, I have to set&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;Validvarname=any;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;without validvarname, it says too long for a sas name in this context.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;with validvarname, error is: statement is not valid or it is used out of proper order.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;with newvar label='This is final total, newvar is being show as the header for variable in the dataset.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;blue blue&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Validvarname is a SAS system option.&lt;/P&gt;
&lt;P&gt;You set it with: options validvarname=any;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where are you using the variable that the LABEL doesn't appear? A few procedures, like proc print, have to be told to use the label. Most procedures will use the label by default or the name and the label. &lt;/P&gt;
&lt;P&gt;If you are looking at the data set using the table viewer then you may have the "show variable name" option set instead of show label.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 00:36:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751378#M236528</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-01T00:36:27Z</dc:date>
    </item>
    <item>
      <title>Re: a proc sql and a case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751386#M236530</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;I use it in proc sql before create table statement.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Blue blue&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 02:56:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751386#M236530</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-07-01T02:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: a proc sql and a case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751391#M236531</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;I use it in proc sql before create table statement.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Blue blue&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Use what? Not very informative.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 03:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751391#M236531</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-01T03:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: a proc sql and a case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751397#M236536</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I changed the place of this:&amp;nbsp;&lt;SPAN&gt;options validvarname=any;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;and I exactly used:&amp;nbsp;&lt;SPAN&gt;options validvarname=any;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;before proc sql.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Blue Blue&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 04:15:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751397#M236536</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-07-01T04:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: a proc sql and a case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751452#M236555</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would have helped greatly if you had put the log along with the code in the post.&lt;BR /&gt;Secondly when you are giving us a code, try to post the code using data sets available in SASHELP.&lt;BR /&gt;Carry out a test run before posting.&lt;BR /&gt;I do not see in any error in the code when I run using SASHELP.CLASS&lt;BR /&gt;I haven't&amp;nbsp; used &lt;STRONG&gt;"option validvarname=any"&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
 create table mytable as
select distinct b.*,
case
when b.age*5 &amp;lt; 35 then 'do this'
when b.age*5 &amp;lt; 50 then 'do that'
else 'Error'
end as 'this is final rate'n, a.name as aname, a.age as aage
from sashelp.class b left outer join sashelp.class a on b.name=a.name;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 13:45:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-proc-sql-and-a-case-statement/m-p/751452#M236555</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-07-01T13:45:32Z</dc:date>
    </item>
  </channel>
</rss>

