04-17-2018 11:13 PM
I'm having trouble keeping a date format when concatenating to a char.
i want to attach a char variable to yesterday's date, for example:
here is the code I made:
yest =today() -1; format yest yymmddn8.;
proc print data=temp0 (keep=yest var2);
The result is:
I've tried a few different things, but can't seem to pin down how to get var2= abc_20180416.
Any tips out there?
04-18-2018 02:51 AM
The crux behind this:
data temp0; format yest yymmddn8.; yest = today() - 1; var1 = 'abc_'; var2 = cat(var1,yest); run;
is that yest is a numeric variable, while cat() is a string function; so you force SAS to do an automatic conversion from numeric to character, and in such automatic conversions, no formats are applied, and you get the raw value (days from 1960-01-01 to yesterday) appended.
@Astounding's solution prevents this.
Hint: never allow automatic type conversions in your programs (you'll find them by the NOTEs they cause). See my Maxims 31 & 25. Take control.
Need further help from the community? Please ask a new question.