Change 2. to Z2, which keeps the leading 0's.
CAT('Yr', year(datepart(a_date)) , 'FW', put(week(datepart(a_date),'v'), Z2.) )
Or use a custom format instead.
Create format:
proc format;
picture myCustomFmt (default=20) low-high = 'Yr%YFW%0U' (datatype=datetime ) ;
run;
use format:
put(a_date, myCustomFmt.) as FW_filter
@yelkenli wrote:
i am having trouble with a simple format need.
My first attempt (which was with CATS and no PUT statement) resulted in single digit weeks for weeks 1 through 9.
The below results in a single digit week number with a blank space where a zero should be. The rest of data manipulations work but I would prefer to have the zero.
The remaining data manipulations provide a table showing a volume over a time line by week (across years, etc.). a second path might be to skip creating this variable and present the data some other way but I have not see that alternate path. so help with keeping the zero is appreciated.
create table want AS
SELECT
some variables
,CAT('Yr', year(datepart(a_date)) , 'FW', put(week(datepart(a_date),'v'), 2.) ) AS FW_filter
from atable;
results are as such:
Yr2017FW 1
Yr2017FW 2
etc.
would like
Yr2017FW01
Yr2017FW02