Reputation: 1537
I want to remove multiple blanks from a string.
%let CDate = 25Mar2015;
data _null_;
call symput('TitleDate',cat(put("&CDate."d,monname9.),', ',year("&CDate."d)));
run;
%put &TitleDate; /* March, 2015 */
%put Title is &TitleDate; /* multiple blanks between 'is' and 'March' */
I tried compress
: %put Title is %sysfunc(compress(&TitleDate));
But it returns Title is March
without year part.
Upvotes: 1
Views: 1496
Reputation: 21274
Very close, two modifications:
WORDDATE20. format instead of the cat/put combinations
call symputx('TitleDate',put("&CDate."d,worddate20.));
EDIT (to answer question in comments): The compress function takes 3 arguments, the first is mandatory and the last two are option.
The compress function doesn't work because what SAS is seeing is:
compress(March 25, 2015) This is an invalid call to the compress function. I think the compress function would assume the second argument would be 2015 and I don't know what it does with the 25. I would actually expect it to generate an error, but it doesn't.
If you did want to use the compress function to pass in a character value you would need to quote it using the %quote function, but that gets rid of all the spaces and I think you just wanted to get rid of the leading spaces.
%put Title is %sysfunc(compress(%quote(&TitleDate.)));
Upvotes: 2