<?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: Adding a new column SAS SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-SAS-SQL/m-p/841395#M332698</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table market as
select *, price-price*0.05 as sale_price label='Sale Price' format=dollar10.2
from market;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Add your format in line with the variable creation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would recommend you look at the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/n02w9rre6jk3n5n10zot9n4uqrzj.htm" target="_self"&gt;documentation examples&lt;/A&gt; to see how SAS SQL works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Oct 2022 22:47:17 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-10-28T22:47:17Z</dc:date>
    <item>
      <title>Adding a new column SAS SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-SAS-SQL/m-p/841384#M332690</link>
      <description>&lt;P&gt;Background&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;STAT 325 HOMEWORK 6 
sql 
Data  description:  Kroger  warehouse,  which  has  two  hubs,  supplies  5  supermarkets  in  local  San  Diego.  
You may want to analyze the sale and logistic record of 2014 by using “proc sql” in SAS.  
market.csv:   
Column 1: Item ID; 
Column 2: Item Name; 
Column 3: Unit Price; 
Column 4: Sale Amount;  
Column 5: Store Branch; 
 
warehouse.csv: 
Column 1: Item ID; 
Column 2: Item Name; 
Column 3: Warehouse Hub Name; 
Column 4: Store Branch; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Add a new column labeled as “Sale Price” for the whole dataset, the sale is 5% off from original price&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*Question 6*/
proc sql;
alter table market
add price num label = 'Sale Price'; 
update Sale Price;
set Sale Price = price*.05;
select item, branch, id, price, amount
from market;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Log&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt; 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 68         
 69         /*Question 6*/
 70         proc sql;
 71         alter table market
 72         add price num label = 'Sale Price';
 NOTE: Table WORK.MARKET has been modified, with 5 columns.
 73         update Sale Price;
                             _
                             79
                             76
 ERROR 79-322: Expecting a SET.
 
 ERROR 76-322: Syntax error, statement will be ignored.
 
 NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
 74         set Sale Price = price*.05;
                ____
                22
                76
 ERROR 22-322: Syntax error, expecting one of the following: MODE, TRANSACTION.  
 
 ERROR 76-322: Syntax error, statement will be ignored.
 
 75         select item, branch, id, price, amount
 76         from market;
 NOTE: Statement not executed due to NOEXEC option.
 77         quit;
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE SQL used (Total process time):
       real time           0.00 seconds
       user cpu time       0.01 seconds
       system cpu time     0.00 seconds
       memory              5989.71k
       OS Memory           33192.00k
       Timestamp           10/28/2022 08:59:23 PM
       Step Count                        1603  Switch Count  0
       Page Faults                       0
       Page Reclaims                     112
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           264
       
 78         
 79         
 80         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 90         &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Oct 2022 21:02:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-SAS-SQL/m-p/841384#M332690</guid>
      <dc:creator>JoshuaG</dc:creator>
      <dc:date>2022-10-28T21:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column SAS SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-SAS-SQL/m-p/841388#M332692</link>
      <description>&lt;P&gt;As a starting point, the &lt;FONT color="#993366"&gt;&lt;STRONG&gt;variable label&lt;/STRONG&gt;&lt;/FONT&gt; is Sale Price, the &lt;FONT color="#0000FF"&gt;variable name&lt;/FONT&gt; is price. You need to refer to it as price (I would rename the column sale_price personally as it sounds like you already have a column named price. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;add &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;price&lt;/STRONG&gt;&lt;/FONT&gt; num &lt;STRONG&gt;&lt;FONT color="#993366"&gt;label = 'Sale Price'&lt;/FONT&gt;&lt;/STRONG&gt;;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;See this worked example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data class;
set sashelp.class;
run;

proc sql;
alter table class
add Year2 num label = 'Weight in Year 2';
update class
set Year2 = weight * 1.05;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;I get the add/modify steps but SAS recreates it anyways so why not use a CREATE TABLE instead?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table market as
select *, price*0.05 as sale_price label='Sale Price'
from market;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/432892"&gt;@JoshuaG&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Background&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;STAT 325 HOMEWORK 6 
sql 
Data  description:  Kroger  warehouse,  which  has  two  hubs,  supplies  5  supermarkets  in  local  San  Diego.  
You may want to analyze the sale and logistic record of 2014 by using “proc sql” in SAS.  
market.csv:   
Column 1: Item ID; 
Column 2: Item Name; 
Column 3: Unit Price; 
Column 4: Sale Amount;  
Column 5: Store Branch; 
 
warehouse.csv: 
Column 1: Item ID; 
Column 2: Item Name; 
Column 3: Warehouse Hub Name; 
Column 4: Store Branch; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Add a new column labeled as “Sale Price” for the whole dataset, the sale is 5% off from original price&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;/*Question 6*/
proc sql;
alter table market
add price num label = 'Sale Price'; 
update Sale Price;
set Sale Price = price*.05;
select item, branch, id, price, amount
from market;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt; 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 68         
 69         /*Question 6*/
 70         proc sql;
 71         alter table market
 72         add price num label = 'Sale Price';
 NOTE: Table WORK.MARKET has been modified, with 5 columns.
 73         update Sale Price;
                             _
                             79
                             76
 ERROR 79-322: Expecting a SET.
 
 ERROR 76-322: Syntax error, statement will be ignored.
 
 NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
 74         set Sale Price = price*.05;
                ____
                22
                76
 ERROR 22-322: Syntax error, expecting one of the following: MODE, TRANSACTION.  
 
 ERROR 76-322: Syntax error, statement will be ignored.
 
 75         select item, branch, id, price, amount
 76         from market;
 NOTE: Statement not executed due to NOEXEC option.
 77         quit;
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE SQL used (Total process time):
       real time           0.00 seconds
       user cpu time       0.01 seconds
       system cpu time     0.00 seconds
       memory              5989.71k
       OS Memory           33192.00k
       Timestamp           10/28/2022 08:59:23 PM
       Step Count                        1603  Switch Count  0
       Page Faults                       0
       Page Reclaims                     112
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           264
       
 78         
 79         
 80         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 90         &lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 21:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-SAS-SQL/m-p/841388#M332692</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-28T21:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column SAS SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-SAS-SQL/m-p/841391#M332694</link>
      <description>&lt;P&gt;How should I go about adding the dollar format here?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 21:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-SAS-SQL/m-p/841391#M332694</guid>
      <dc:creator>JoshuaG</dc:creator>
      <dc:date>2022-10-28T21:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column SAS SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-SAS-SQL/m-p/841392#M332695</link>
      <description>I was able to get it to output, need help with the formatting now</description>
      <pubDate>Fri, 28 Oct 2022 21:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-SAS-SQL/m-p/841392#M332695</guid>
      <dc:creator>JoshuaG</dc:creator>
      <dc:date>2022-10-28T21:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column SAS SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-SAS-SQL/m-p/841394#M332697</link>
      <description>&lt;P&gt;I tried adding it like this:&lt;/P&gt;&lt;P&gt;/*Question 6*/&lt;BR /&gt;proc sql;&lt;BR /&gt;create table market as&lt;BR /&gt;select *, price-price*0.05 as sale_price label='Sale Price'&lt;BR /&gt;from market;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select item, branch, id, price, amount, sale_price&lt;BR /&gt;from market;&lt;BR /&gt;format sale_price=Dollar10.2;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, it still isnt showing up&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 21:57:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-SAS-SQL/m-p/841394#M332697</guid>
      <dc:creator>JoshuaG</dc:creator>
      <dc:date>2022-10-28T21:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column SAS SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-SAS-SQL/m-p/841395#M332698</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table market as
select *, price-price*0.05 as sale_price label='Sale Price' format=dollar10.2
from market;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Add your format in line with the variable creation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would recommend you look at the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/n02w9rre6jk3n5n10zot9n4uqrzj.htm" target="_self"&gt;documentation examples&lt;/A&gt; to see how SAS SQL works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 22:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-SAS-SQL/m-p/841395#M332698</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-28T22:47:17Z</dc:date>
    </item>
  </channel>
</rss>

