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

Hello,

 

I have two datasets located at two different folders and each of them has it's own format. i want the sas automatically search their format and apply the format to their related datasets. i also need to combine these two dataset to create one dataset to do some comparison and analysis. some variables name are the same in both dataset but with different format. i am not sure how to do it in sas. any ideas?

1 ACCEPTED SOLUTION

Accepted Solutions
juliajulia
Obsidian | Level 7

Thanks. Let me try to see how this works. my purpose is to check to see if the same format has been applied to the same variable in both datasets.

 

View solution in original post

2 REPLIES 2
ballardw
Super User

@juliajulia wrote:

Hello,

 

I have two datasets located at two different folders and each of them has it's own format. i want the sas automatically search their format and apply the format to their related datasets. i also need to combine these two dataset to create one dataset to do some comparison and analysis. some variables name are the same in both dataset but with different format. i am not sure how to do it in sas. any ideas?


You can apply a format to a data set in place using Proc Datasets and the Modify statement.

But before we go there you may not actually need to do so. Since you say you will combine the data sets I would start there.

 

You can use a data step to append two data sets with a SET statement (to "stack") or MERGE (combine rows from both usually on common variables.

Example of SET

 

data want;
   set lib1.datasetname lib2.otherdatasetname;
run;

When you do this variables of the same name will inherit the formats and labels of the first encountered use, such as in lib1.datasetname. No need to change the formats if those are the ones you want.

If that is not what you need then you add a format statement to the data step that combines the data to the format you want.

 

To "automatically" do what you are requiring may have some pitfalls. By Folder I hope you have different libraries assigned as that is going to be the key location that SAS uses.

How do we identify "related datasets". That phrase makes me guess that there are some rules about applying formats from some data sets to specific others and not all in the other library.

 

But before you get there, have you verified that the variables are of the same types? You can't apply numeric formats to character values and vice versa. If your same named variables are different types you will not be able to combine the data at all.

juliajulia
Obsidian | Level 7

Thanks. Let me try to see how this works. my purpose is to check to see if the same format has been applied to the same variable in both datasets.

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1892 views
  • 0 likes
  • 2 in conversation