<?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 ignoring capitalized variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-ignoring-capitalized-variable/m-p/876308#M346231</link>
    <description>&lt;P&gt;Example data in the form of data step that exhibits this behavior with shown. Since the only variable needed is your Clin_clean I would hope that is relatively easy.(See my example below)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What format is currently applied to your Clin_clean variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: You want to make sure that the variable has the values correct before using groupby in the syntax you show. If the Clin_clean has different case on input you will get multiple groups because Group By is not using the calculated version of the Clin variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;datalines;
abc
abc
Abc
AbC
pdq 
pdq
pdq
;

proc sql;
create table clin_counts as
select upper(clin_clean) as clin, count(clin_clean) as num_recs
from clean_clin
group by clin_clean
order by num_recs;
quit;

ods listing;
proc print data=clin_counts noobs;
run;

/* result*/
clin    num_recs
ABC         1
ABC         1
ABC         2
PDQ         3


&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 May 2023 19:24:53 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-05-17T19:24:53Z</dc:date>
    <item>
      <title>PROC SQL ignoring capitalized variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-ignoring-capitalized-variable/m-p/876283#M346218</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a proc sql step which is building some counts by clinic:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table clin_counts as&lt;BR /&gt;select upper(clin_clean) as clin, count(clin_clean) as num_recs&lt;BR /&gt;from clean_clin&lt;BR /&gt;group by clin_clean&lt;BR /&gt;order by num_recs;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The step works but I'm confused because clin_clean is all upper case, while the resulting variable after this step (clin) is not.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I added the upper function to the SQL step, but the resulting values are still all lower case.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is much appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2023 17:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-ignoring-capitalized-variable/m-p/876283#M346218</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2023-05-17T17:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL ignoring capitalized variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-ignoring-capitalized-variable/m-p/876285#M346219</link>
      <description>&lt;P&gt;That is surprising. Can you post the log from running:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table clin_counts as
select upper(clin_clean) as clin, count(clin_clean) as num_recs
from clean_clin
group by clin_clean
order by num_recs;
quit;

data _null_;
  set clin_counts(obs=5);
  put clin= num_recs=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2023 17:16:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-ignoring-capitalized-variable/m-p/876285#M346219</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-05-17T17:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL ignoring capitalized variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-ignoring-capitalized-variable/m-p/876286#M346220</link>
      <description>&lt;P&gt;Please post your log.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table clin_counts as
select upper(clin_clean) as clin, count(clin_clean) as num_recs
from clean_clin
group by clin_clean
order by num_recs;
quit;

 proc print data=clin_counts (obs=5);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2023 17:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-ignoring-capitalized-variable/m-p/876286#M346220</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-17T17:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL ignoring capitalized variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-ignoring-capitalized-variable/m-p/876308#M346231</link>
      <description>&lt;P&gt;Example data in the form of data step that exhibits this behavior with shown. Since the only variable needed is your Clin_clean I would hope that is relatively easy.(See my example below)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What format is currently applied to your Clin_clean variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: You want to make sure that the variable has the values correct before using groupby in the syntax you show. If the Clin_clean has different case on input you will get multiple groups because Group By is not using the calculated version of the Clin variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;datalines;
abc
abc
Abc
AbC
pdq 
pdq
pdq
;

proc sql;
create table clin_counts as
select upper(clin_clean) as clin, count(clin_clean) as num_recs
from clean_clin
group by clin_clean
order by num_recs;
quit;

ods listing;
proc print data=clin_counts noobs;
run;

/* result*/
clin    num_recs
ABC         1
ABC         1
ABC         2
PDQ         3


&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2023 19:24:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-ignoring-capitalized-variable/m-p/876308#M346231</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-17T19:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL ignoring capitalized variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-ignoring-capitalized-variable/m-p/876330#M346240</link>
      <description>&lt;P&gt;You appear to be grouping by a different variable than you are including in the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example that makes it much clearer.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select mod(age,3) as mod_age,count(*) as nobs
from sashelp.class
group by age
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt; mod_age      nobs
------------------
       2         2
       0         5
       1         3
       2         4
       0         4
       1         1

&lt;/PRE&gt;
&lt;P&gt;Also you probably need to include the CALCULATED keyword in the GROUP BY clause to make sure it is not grouping by some variable in CLEAN_CLIN that is named CLIN instead of the new CLIN variable you are calculating the in the SELECT statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also do you really want the count to be zero for the group of records where CLIN_CLEAN is missing?&amp;nbsp; That is what happens when you use a variable inside the COUNT() function, missing values are not counted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table clin_counts as
select upper(clin_clean) as clin
     , count(*) as num_recs
from clean_clin
group by calculated clin 
order by num_recs;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2023 21:38:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-ignoring-capitalized-variable/m-p/876330#M346240</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-17T21:38:30Z</dc:date>
    </item>
  </channel>
</rss>

