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;
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.
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.
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.
Thank you for your help!
It totally makes sense to me now.
Thank you very much!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.