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

Hi SAS community,

GOAL is to merge 2 datasets.      
The BY Variable in the existing dataset is character      
Alphabetic List of Variables and Attributes      
#VariableTypeLenFormatLabel 
1Mfr_Item_MINChar5017Mfr Item MIN 
       
The BY Variable in the new_dataset is numeric      
Alphabetic List of Variables and Attributes      
#VariableTypeLenFormatInformatLabel
11SCCNum8BEST. 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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

View solution in original post

2 REPLIES 2
ballardw
Super User

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.

 

Gladis6680
Obsidian | Level 7

Thank you very much!!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2725 views
  • 1 like
  • 2 in conversation