BookmarkSubscribeRSS Feed
knighsson
Obsidian | Level 7

Hello!

I have a question about concatenating tables with multiple rename statement. Could you please confirm the syntax of the first way is accurate or not?

in addition, can the second way to code get the same results from the first way to code?

 

Thank you!

 

First:

 

data nh.diabetes_4yr;

set NH.DIQ_c 

NH.DIQ_d (rename=(DID040=DID040Q) rename=(DID060=DID060G) rename=(DID070=DIQ070));

run;

 

 

Second:

 

data nh.diabetes_4yr;

set NH.DIQ_c

NH.DIQ_d (rename=(DID040=DID040Q));

run;

 

data nh.diabetes_4yr;

set NH.DIQ_c

NH.DIQ_d (rename=(DID060=DID060G));

run;

 

data nh.diabetes_4yr;

set NH.DIQ_c

NH.DIQ_d (rename=(DID070=DIQ070));

run;

6 REPLIES 6
PaigeMiller
Diamond | Level 26
data nh.diabetes_4yr;
    set NH.DIQ_c 
    NH.DIQ_d (rename=(DID040=DID040Q DID060=DID060G DID070=DIQ070));
run;

The second way also requires some changes, and is pretty inefficient, I would do it as above.

--
Paige Miller
knighsson
Obsidian | Level 7
Thank you, I thought the second way may overwrite the nh.diabetes_4yr. So I want to double check.

Thank you!
ballardw
Super User

Not really sure what you question is.

 

When you have multiple variables in ONE data set to rename you can save a lot of typing and possible confusion with parentheses by using multiple pairs in a single rename grouping such as:

 

datasetname (rename=(oldname1=newname1  oldname2=newname2 oldname3=newname3)).

 

Your code doesn't throw an error but requires lots of extra typing with the ever present more typing=> more chances to make a typo.

 

 

Your "Second" method overwrites the same output data set two times and only the effect of the last data step will have one variable renamed. The third iteration of nh.diabetes_4yr would have both DID040 and DID060 from the NH.DIQ_d data set.

 

 

knighsson
Obsidian | Level 7
Thank you so much! You answered my question and it is helpful.

Thank you!
Tom
Super User Tom
Super User

The first method works but it is much more verbose than what is needed. Just list all of the old=new pairs in a single RENAME= list.

 

data nh.diabetes_4yr;
  set
    NH.DIQ_c 
    NH.DIQ_d (rename=(DID040=DID040Q DID060=DID060G DID070=DIQ070))
  ;
run;

 

The second method cannot work since each step is overwriting the target dataset.  Only the results of the final data step will be available.

 

 

 

knighsson
Obsidian | Level 7

Thank you for your help!

It totally makes sense to me now.

Thank you very much!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 496 views
  • 0 likes
  • 4 in conversation