BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Sven111
Pyrite | Level 9
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

7 REPLIES 7
Sven111
Pyrite | Level 9
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;
ybz12003
Rhodochrosite | Level 12

Thanks

elwayfan446
Barite | Level 11

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.

ChrisHemedinger
Community Manager

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.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
elwayfan446
Barite | Level 11
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.
ballardw
Super User

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

ybz12003
Rhodochrosite | Level 12

yes, you worked on it before?

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 80039 views
  • 3 likes
  • 5 in conversation