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?
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.
@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.
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.
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.
Ready to level-up your skills? Choose your own adventure.