Help using Base SAS procedures

How to rename variable in PROC SQL?

Accepted Solution Solved
Reply
Super Contributor
Posts: 297
Accepted Solution

How to rename variable in PROC SQL?

Hello,

 

I would like to rename the following variable in Proc SQL although I know it could be done in SAS data steps.  But I would like to use in PROC SQL, how?  Thanks.

 

data dataout.rename;

      set dataout.test;

      rename HAVARTH3=AR _PRACE=RACE _AGEG5YR=AGE _INCOMG=INCOME _HCVU651=INSURANCE _BMI5CAT=BMI

            LMTJOIN3=LMTJOIN  DRNKANY5=DRNKANY   DIABETE3=DIABETE _SMOKER3=SMOKER;

run;


Accepted Solutions
Solution
‎02-08-2017 08:25 PM
Frequent Contributor
Posts: 82

Re: How to rename variable in PROC SQL?

PROC SQL;
    CREATE TABLE dataout.rename AS
        SELECT  HAVARTH3        AS AR 
               ,_PRACE          AS RACE
               ,_AGEG5YR        AS AGE 
               ,_INCOMG         AS INCOME
               ,_HCVU651        AS INSURANCE 
               ,_BMI5CAT        AS BMI
               ,LMTJOIN3        AS LMTJOIN
               ,DRNKANY5        AS DRNKANY
               ,DIABETE3        AS DIABETE
               ,_SMOKER3        AS SMOKER
       FROM     dataout.test;
;QUIT;

View solution in original post


All Replies
Solution
‎02-08-2017 08:25 PM
Frequent Contributor
Posts: 82

Re: How to rename variable in PROC SQL?

PROC SQL;
    CREATE TABLE dataout.rename AS
        SELECT  HAVARTH3        AS AR 
               ,_PRACE          AS RACE
               ,_AGEG5YR        AS AGE 
               ,_INCOMG         AS INCOME
               ,_HCVU651        AS INSURANCE 
               ,_BMI5CAT        AS BMI
               ,LMTJOIN3        AS LMTJOIN
               ,DRNKANY5        AS DRNKANY
               ,DIABETE3        AS DIABETE
               ,_SMOKER3        AS SMOKER
       FROM     dataout.test;
;QUIT;
Super Contributor
Posts: 297

Re: How to rename variable in PROC SQL?

Thanks

Frequent Contributor
Posts: 140

Re: How to rename variable in PROC SQL?

Can you tell me why the renamed columns don't export to excel using ods excel file = "" ?  The regular variable names are what get exported instead.

Community Manager
Posts: 2,761

Re: How to rename variable in PROC SQL?

Hi @elwayfan446, this sounds like a new question.  Want to create a new topic with some sample code?  ODS EXCEL is for ODS output, not data sets exactly, so it doesn't really play into PROC SQL unless you're leaving off the CREATE TABLE statement.

Frequent Contributor
Posts: 140

Re: How to rename variable in PROC SQL?

Thanks Chris. I was using the output method but you bringing up the create table statement made me realize that creating a temp table and using proc export was much easier and fixed my problem.
Super User
Posts: 10,500

Re: How to rename variable in PROC SQL?

Unrelated question: Is there any chance this data is coming from BRFSS?

Super Contributor
Posts: 297

Re: How to rename variable in PROC SQL?

yes, you worked on it before?

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 3561 views
  • 2 likes
  • 5 in conversation