<?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 Issue with sas program proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-sas-program-proc-sql/m-p/872066#M344515</link>
    <description>&lt;P&gt;Proc content output&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;# Variable Type Len Format12543 &lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;Char&lt;/TD&gt;&lt;TD&gt;31&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;Char&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;Num&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;PERCENT10.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;d&lt;/TD&gt;&lt;TD&gt;Num&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;PERCENT10.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;e&lt;/TD&gt;&lt;TD&gt;Num&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;PERCENT10.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to add a value to the last row of the dataset which is the mean value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code:&lt;BR /&gt;proc sql;&lt;BR /&gt;select mean(c)*100 into :orr_pct from Efficacy;&lt;/P&gt;&lt;P&gt;select mean(d)*100 into :orrc_pct from Efficacy;&lt;BR /&gt;select mean(e)*100 into :dcr_pct from Efficacy;&lt;BR /&gt;insert into eff_all2(Cohort_new, N, c, d,e)&lt;BR /&gt;values ("Total","&amp;amp;ne_allt",put(&amp;amp;orr_pct,8.2),put(&amp;amp;orrc_pct,8.2),put(&amp;amp;dcr_pct, 8.2));&lt;/P&gt;&lt;P&gt;quit;&lt;BR /&gt;&lt;BR /&gt;I get an error:&amp;nbsp;&lt;BR /&gt;&lt;SPAN&gt;Error: proc sql; 237 insert into eff_all2 238 values ("Total", &amp;amp;ne_allt, put(&amp;amp;orrc_pct, 8.2), put(&amp;amp;orr_pct, 8.2), put(&amp;amp;dcr_pct, 8.2)); ___ _ 22 200 202 ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant, a missing value, ), +, ',', -, MISSING, NULL, USER. ERROR 200-322: The symbol is not recognized and will be ignored. ERROR 202-322: The option or parameter is not recognized and will be ignored.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;The put command keeps giving me error.&amp;nbsp;&lt;BR /&gt;When i insert without the put value i get the output but the decimal pint is mi&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 25 Apr 2023 23:34:52 GMT</pubDate>
    <dc:creator>Kp1234</dc:creator>
    <dc:date>2023-04-25T23:34:52Z</dc:date>
    <item>
      <title>Issue with sas program proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-sas-program-proc-sql/m-p/872066#M344515</link>
      <description>&lt;P&gt;Proc content output&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;# Variable Type Len Format12543 &lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;Char&lt;/TD&gt;&lt;TD&gt;31&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;Char&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;Num&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;PERCENT10.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;d&lt;/TD&gt;&lt;TD&gt;Num&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;PERCENT10.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;e&lt;/TD&gt;&lt;TD&gt;Num&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;PERCENT10.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to add a value to the last row of the dataset which is the mean value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code:&lt;BR /&gt;proc sql;&lt;BR /&gt;select mean(c)*100 into :orr_pct from Efficacy;&lt;/P&gt;&lt;P&gt;select mean(d)*100 into :orrc_pct from Efficacy;&lt;BR /&gt;select mean(e)*100 into :dcr_pct from Efficacy;&lt;BR /&gt;insert into eff_all2(Cohort_new, N, c, d,e)&lt;BR /&gt;values ("Total","&amp;amp;ne_allt",put(&amp;amp;orr_pct,8.2),put(&amp;amp;orrc_pct,8.2),put(&amp;amp;dcr_pct, 8.2));&lt;/P&gt;&lt;P&gt;quit;&lt;BR /&gt;&lt;BR /&gt;I get an error:&amp;nbsp;&lt;BR /&gt;&lt;SPAN&gt;Error: proc sql; 237 insert into eff_all2 238 values ("Total", &amp;amp;ne_allt, put(&amp;amp;orrc_pct, 8.2), put(&amp;amp;orr_pct, 8.2), put(&amp;amp;dcr_pct, 8.2)); ___ _ 22 200 202 ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant, a missing value, ), +, ',', -, MISSING, NULL, USER. ERROR 200-322: The symbol is not recognized and will be ignored. ERROR 202-322: The option or parameter is not recognized and will be ignored.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;The put command keeps giving me error.&amp;nbsp;&lt;BR /&gt;When i insert without the put value i get the output but the decimal pint is mi&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 25 Apr 2023 23:34:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-sas-program-proc-sql/m-p/872066#M344515</guid>
      <dc:creator>Kp1234</dc:creator>
      <dc:date>2023-04-25T23:34:52Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with sas program proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-sas-program-proc-sql/m-p/872074#M344518</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/304341"&gt;@Kp1234&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Couple of things to keep in mind.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The PUT function/statement converts numeric to character. Therefore when you try populate a numeric column/field with a character value you'll get an error!&lt;/LI&gt;
&lt;LI&gt;Macro variables are typically treated as character variables&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this code&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   select 
     put((mean(c)*100),8.2)
    , put((mean(d)*100),8.2)
    , put((mean(e)*100),8.2)
   into :orr_pct, :orrc_pct, :dcr_pct
   from Efficacy;
   insert into eff_all2(Cohort_new, N, c, d,e)
   values ("Total","&amp;amp;ne_allt",&amp;amp;orr_pct,&amp;amp;orrc_pct,&amp;amp;dcr_pct);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Apr 2023 23:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-sas-program-proc-sql/m-p/872074#M344518</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2023-04-25T23:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with sas program proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-sas-program-proc-sql/m-p/872075#M344519</link>
      <description>&lt;P&gt;Let's work backwards here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First thing is that the VALUES clause wants actual VALUES and not EXPRESSIONS.&lt;/P&gt;
&lt;P&gt;So if C,D and E are NUMERIC variables then do this&amp;nbsp; The number of decimal places in the value inserted makes no difference.&amp;nbsp; .80 and .8 are the exact same number.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;insert into eff_all2(Cohort_new, N, c, d,e)
values ("Total","&amp;amp;ne_allt",&amp;amp;orr_pct,&amp;amp;orrc_pct,&amp;amp;dcr_pct);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the C, D and E are character variables like COHORT_NEW and N then you need to add quotes around the values.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;insert into eff_all2(Cohort_new, N, c, d,e)
values ("Total","&amp;amp;ne_allt","&amp;amp;orr_pct","&amp;amp;orrc_pct","&amp;amp;dcr_pct");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that if you could have used an expression then the PUT() function would have only worked if C, D and E were CHARACTER variables because formats always generate CHARACTER strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What type of numbers are original C, D and E values?&amp;nbsp; Why did you multiple they mean by 100?&amp;nbsp; The PERCENT format expects actual percentages as the values.&amp;nbsp; So 50% would be the number 0.50.&amp;nbsp; If you multiply by 100 and the display it with the PERCENT format you will get 5000% instead of 50%.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally why the heck are you generating the macro variables at all?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
insert into eff_all2(Cohort_new, N, c, d,e)
select "Total","&amp;amp;ne_allt",mean(c),mean(d),mean(e) 
  from Efficacy
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 00:09:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-sas-program-proc-sql/m-p/872075#M344519</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-26T00:09:54Z</dc:date>
    </item>
  </channel>
</rss>

