1
votes

I have a need to combine two sas datasets having the same column names but one of the datasets will have a numeric value where the same name in the other dataset are character. I was thinking to evaluate each field with the %isnum function and based on this convert the number to character:

char_id = put(id, 7.) ; 
drop id ; 
rename char_id=id ;

What I need to know is how do I determine the length of the variable to use in the PUT and what would I do for date fields?

2

2 Answers

0
votes

Sounds like you need to analyze your data and see how long things are. Use an obviously too long format (best32.) and then see how long the actual results are, or use max.

For date fields, you need to decide how you want your date fields to look.

date_c = put(date_n,date9.);

That would be the default, but there are literally hundreds of date formats you can choose from.

0
votes

You can also use proc contents data=myDataStes out=VarDatasets; run; and you will get the list of variables with type, length, format, informat and so on.