BookmarkSubscribeRSS Feed
Aar684
Calcite | Level 5
Hi all,

This is probably a basic question, but I cannot seem to find the answer. I have 2 datasets, one is SAS dataset and the other is an .xls file. Both files have the same variables. I need to combine the two datasets into one. This is obviously very simple.

Data number3;
set number1 number2;
run;

However, one of the variables is assigned as both character and numeric, therefore not allowing the data to combine. Is there another way to combine these or is there a way to convert variables to char or numeric without changing the variable name? Thanks in advance for any help people can provide.
1 REPLY 1
Peter_C
Rhodochrosite | Level 12
the data step that does the combining can do the numeric to character conversion.
For example, suppose the sas data has a string containing a numeric key like credit card number (but shorter, say length 9), and excel provides that in a numeric column: [pre]data together ;
set sas_data excel_data( rename=( key=nkey) in= fromexcel);
if fromexcel then key= put( nkey, best9.);
drop nkey ;
run ;[/pre]
does this look like what's wanted?

PeterC

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—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
  • 1 reply
  • 878 views
  • 0 likes
  • 2 in conversation