<?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: Renaming Colums in  PROC SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Renaming-Colums-in-PROC-SQL/m-p/952369#M372218</link>
    <description>&lt;P&gt;Your PROC PRINT is not right should be&lt;/P&gt;
&lt;PRE&gt;proc print data=&lt;STRONG&gt;product_data&lt;/STRONG&gt; noobs;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And using system option VALIDVARNAME=ANY to make it happend. Here is an example:&lt;/P&gt;
&lt;PRE&gt;data have;
 set sashelp.class;
run;


options validvarname=any;
proc sql ;
create table temp as
select * from have;

create table have as 
 select * 
 from temp(rename=(name="Eng Name"n  sex="Female Male"n  age='age  age'n));
quit;
proc print data=have noobs;run;
&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1733193466464.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102650iAB01A1EDF24815A2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1733193466464.png" alt="Ksharp_0-1733193466464.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Dec 2024 02:37:53 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-12-03T02:37:53Z</dc:date>
    <item>
      <title>Renaming Colums in  PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-Colums-in-PROC-SQL/m-p/952348#M372208</link>
      <description>&lt;P&gt;So, I have some data that looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data product_data;
    input prodnum $ 1-4 prodname $ 6-27 manunum $ 29-31 prodtype $ 33-43 rtlcost 45-49; 
	format rtlcost dollar8.2;
    cards;
5119 Dream Machine          500 Workstation 3200 
4216 Business Machine       450 Workstation 3215 
5112 Office Phone           560 Phone       172 
3110 Spreadsheet Software   134 Software    300 
1230 Database Software      113 Software    757 
3431 Statistical Software   243 Software    1789 
2102 Wordprocessor Software 245 Software    423 
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am running proc sql to apply price increase/decrease to some of the products:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
    /* 20% price increase for all Software products */
    update product_data
    set rtlcost = rtlcost * 1.20
    where prodtype = 'Software';

    /* 20% price decrease for all other products */
    update product_data
    set rtlcost = rtlcost * 0.80
    where prodtype not like 'Software';
quit;

proc print data=product_data noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there a way to rename the column names in proc sql, and &lt;STRONG&gt;NOT&lt;/STRONG&gt; in proc print or the data step? Like for example, renaming "prodnum" as Product Number, "prodname" as Product Name, "manunum" as Manufacturer Number, etc.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2024 23:09:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-Colums-in-PROC-SQL/m-p/952348#M372208</guid>
      <dc:creator>unwashedhelimix</dc:creator>
      <dc:date>2024-12-02T23:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming Colums in  PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-Colums-in-PROC-SQL/m-p/952349#M372209</link>
      <description>&lt;P&gt;Use a LABEL statement in a DATA step, or a LABEL= option in SQL to assign pretty strings to variables for display.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2024 23:06:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-Colums-in-PROC-SQL/m-p/952349#M372209</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-12-02T23:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming Colums in  PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-Colums-in-PROC-SQL/m-p/952362#M372214</link>
      <description>&lt;P&gt;You could create a new table to override the original one.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.class;
run;


proc sql undopolicy=none;
create table have as
select name as Eng_Name,sex as Female_Male   ,age,weight,height
 from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql undopolicy=none;
create table have as
select *
 from have(rename=(name=Eng_Name sex=Female_Male));
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.class;
run;


proc sql ;
create table temp as
select *
 from have(rename=(name=Eng_Name sex=Female_Male));

create table have as select * from temp;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you could create a VIEW for this purpose, which don't occupy the size of storage.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql ;
create view have2 as
select name as Eng_Name,sex as Female_Male   ,age,weight,height
 from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2024 01:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-Colums-in-PROC-SQL/m-p/952362#M372214</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-12-03T01:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming Colums in  PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-Colums-in-PROC-SQL/m-p/952367#M372217</link>
      <description>&lt;P&gt;How can I input nicer strings? I tried this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;

	create table temp as
	select *
	from product_data(rename=(prodnum='Product Number' prodname='Product Name'));

	create table product_data as select * from temp;
quit;

title "Product Information";
proc print data=temp noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but it doesn't rename the column headings. It works when I do something like prodnum=Product_Number, but I want spaces rather than underscores.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2024 02:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-Colums-in-PROC-SQL/m-p/952367#M372217</guid>
      <dc:creator>unwashedhelimix</dc:creator>
      <dc:date>2024-12-03T02:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming Colums in  PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-Colums-in-PROC-SQL/m-p/952369#M372218</link>
      <description>&lt;P&gt;Your PROC PRINT is not right should be&lt;/P&gt;
&lt;PRE&gt;proc print data=&lt;STRONG&gt;product_data&lt;/STRONG&gt; noobs;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And using system option VALIDVARNAME=ANY to make it happend. Here is an example:&lt;/P&gt;
&lt;PRE&gt;data have;
 set sashelp.class;
run;


options validvarname=any;
proc sql ;
create table temp as
select * from have;

create table have as 
 select * 
 from temp(rename=(name="Eng Name"n  sex="Female Male"n  age='age  age'n));
quit;
proc print data=have noobs;run;
&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1733193466464.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102650iAB01A1EDF24815A2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1733193466464.png" alt="Ksharp_0-1733193466464.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2024 02:37:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-Colums-in-PROC-SQL/m-p/952369#M372218</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-12-03T02:37:53Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming Colums in  PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-Colums-in-PROC-SQL/m-p/952377#M372223</link>
      <description>&lt;P&gt;If you want to name the variables using strings that are not valid SAS names you have to first set the VALIDVARNAME option to ANY.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;After that you will have to use NAME LITERALS in your code to create or reference any name that is not a normal valid SAS name.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Your example SQL code does not have any steps that would make it possible to rename the variables&lt;/STRONG&gt;, since all you are showing are UPDATE statements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in other more normal SQL code you could rename the variables when you list them in the SELECT clause of your CREATE TABLE statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table want as
  select prodnum as 'Product Number'n
       , prodname as 'Product Name'n
       , manunum as 'Manufacturer Number'n
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or use the RENAME= dataset option on either the output dataset reference&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table want(rename=
        (prodnum='Product Number'n
         prodname='Product Name'n
         manunum='Manufacturer Number'n ....))
  as select ....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or rename them on the way IN (remember to use the new names in the code)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;... from have(rename=(....)) ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Not sure why you are using SQL code for this problem however.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would much simpler in normal SAS code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set product_data;
  if (prodtype = 'Software')&amp;nbsp;then&amp;nbsp;rtlcost = rtlcost * 1.20;
&amp;nbsp;&amp;nbsp;else&amp;nbsp;rtlcost = rtlcost * 0.80;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you are going to use the UPDATE statement of PROC SQL your example can be done in one STEP by using a CASE clause to select the right cost adjustment factor for each observation.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;update product_data
set rtlcost = rtlcost * case when (prodtype = 'Software') then 1.20 else 0.80 end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Dec 2024 03:34:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-Colums-in-PROC-SQL/m-p/952377#M372223</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-03T03:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming Colums in  PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-Colums-in-PROC-SQL/m-p/952378#M372224</link>
      <description>&lt;P&gt;"Column Headings"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you just looking for how to attach LABELS to your variables?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=product_data label noobs;
label prodnum='Product Number' prodname='Product Name';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Dec 2024 03:36:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-Colums-in-PROC-SQL/m-p/952378#M372224</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-03T03:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming Colums in  PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-Colums-in-PROC-SQL/m-p/952413#M372234</link>
      <description>&lt;P&gt;Do not saddle yourself with those stupid name literals. &lt;U&gt;&lt;STRONG&gt;Labels&lt;/STRONG&gt;&lt;/U&gt; are made for pretty strings, so use them, but keep &lt;U&gt;&lt;STRONG&gt;variable names&lt;/STRONG&gt;&lt;/U&gt; simple for easier coding.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2024 11:28:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-Colums-in-PROC-SQL/m-p/952413#M372234</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-12-03T11:28:16Z</dc:date>
    </item>
  </channel>
</rss>

