BookmarkSubscribeRSS Feed
Tecla1
Quartz | Level 8

Good Afternoon,

I need to use a proc sql with two DB that has the same columns (name), so I think I have to rename the columns of one of the two tables (I need to Keep all the columns of the two DB), but I have a big number of columns and it's not so easy to list all. I find some soluction with "Index" function but I'm not able to use it. Please can you help me ?

 

Tnks a lot.

Tecla

2 REPLIES 2
Reeza
Super User

If you have the same column names what are you trying to do overall?

Sometimes it makes more sense to append and transpose?

 

You can add a prefix/suffix to all the variables as well, which is another option. If your table name was SAMPLE in the WORK library this would add the NEW_ prefix to each variable name. Note that it is case sensitive for the comparisons.

 

Let prefix = new_;

proc sql noprint;
select catx("=", name, catx("_", "&prefix.", name))
into :rename_list
separated by " "
from sashelp.vcolumn
where libname='WORK'
and memname='SAMPLE';
quit;


%put &rename_list;


proc datasets library=work nodetails nolist;
modify sample;
rename &rename_list;
run; quit;

proc print data=sample noobs;
run;
ballardw
Super User

It will help to provide a clear example of what your are attempting to do. As in show a sample of the two data sets, maybe 5 variables each where you have the "same columns" and what the result is expected to be when things are done.

 

And perhaps SQL isn't what you need. The data step allows uses of variable name lists that may make things easier. But without seeing a pretty concrete example of what you need it is hard to tell.

 

Best is if the data could be provided in the form of a data step so we have something to manipulate. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the <> icon or attached as text to show exactly what you have and that we can test code against.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 532 views
  • 0 likes
  • 3 in conversation