Hi SAS community,
GOAL is to merge 2 datasets. | ||||||
The BY Variable in the existing dataset is character | ||||||
Alphabetic List of Variables and Attributes | ||||||
# | Variable | Type | Len | Format | Label | |
1 | Mfr_Item_MIN | Char | 50 | 17 | Mfr Item MIN | |
The BY Variable in the new_dataset is numeric | ||||||
Alphabetic List of Variables and Attributes | ||||||
# | Variable | Type | Len | Format | Informat | Label |
11 | SCC | Num | 8 | BEST. | SCC |
I would like to convert the numeric variable from the new dataset into a charater variable. |
my code |
data trial; |
length SCC_1 $50; |
set new_dataset |
SCC_1=put(SCC, 17.); |
drop SCC; |
rename SCC_1=Mfr_Item_MIN; |
run; |
proc sort data=trial; |
by Mfr_Item_MIN; |
run; |
proc sort data=existing_dataset; |
by Mfr_Item_MIN; |
run; |
data merge_data; |
merge trial(in=a); |
existing_dataset(in=b); |
if a & b; |
by Mfr_Item_MIN; |
run; |
But I have 0 obeservations in the merge_data file and I know there are commons items in both datasets. |
Thank you for help.
In this code
data trial; length SCC_1 $50; set new_dataset SCC_1=put(SCC, 17.); drop SCC; rename SCC_1=Mfr_Item_MIN; run;
Look closely at the value of SCC_1 or Mfr_item_min. You will likely see a bunch of leading blank spaces when SCC is not 17 digits.
So you didn't get matches.
The PUT function will right justify numeric results by default. Use something like
put(SCC, 17. -L) to left justify the result.
And what is with the new variable and rename? Create the variable as desired name.
Better is to check that you READ the values as intended, i.e. SCC should have been as character to begin with. You can get into precision of storage with long numeric values and 17 digits is an indicator that you may not actually have the values that you need as 16 digits is generally the precision SAS has available.
In this code
data trial; length SCC_1 $50; set new_dataset SCC_1=put(SCC, 17.); drop SCC; rename SCC_1=Mfr_Item_MIN; run;
Look closely at the value of SCC_1 or Mfr_item_min. You will likely see a bunch of leading blank spaces when SCC is not 17 digits.
So you didn't get matches.
The PUT function will right justify numeric results by default. Use something like
put(SCC, 17. -L) to left justify the result.
And what is with the new variable and rename? Create the variable as desired name.
Better is to check that you READ the values as intended, i.e. SCC should have been as character to begin with. You can get into precision of storage with long numeric values and 17 digits is an indicator that you may not actually have the values that you need as 16 digits is generally the precision SAS has available.
Thank you very much!!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.