user3934760
user3934760

Reputation: 95

Concatenate date with character variable ,SAS

I'm facing an issue where I cannot concatenate a date formatted variable with a character variable. The date format is 'date9.'. What happens is that the date turns into numbers when the concatenation is done.

Example:

Agency: RCL Date: 24MAR2008

Result: RCL17615

It should be: RCL24MAR2008

This is my code:

data work.collectionrate_new;
set work.collectionrate;
tran_id=compress(agency||date);
run;

Thank you.

Upvotes: 1

Views: 7571

Answers (1)

momo1644
momo1644

Reputation: 1804

you just need a put(date,date9.) to format your date as character:

Code:

data new;
format  date date9. ;
date="24MAR2008"d;
agency="RCL";
tran_id=cats(agency,put(date,date9.));
put _all_;
run;

Output:

date=24MAR2008 agency=RCL tran_id=RCL24MAR2008

Upvotes: 3

Related Questions