DATA Step, Macro, Functions and more

week function

Reply
Frequent Contributor
Posts: 110

week function

I'm using the following function:  week_function=week(dt,'u');  For weeks 0-9 (i.e. January - March), SAS only returns a single value I.e. 0, 1, 2, 3, 4 etc.  However, I would like SAS to return a two value digit instead, so

0 --> 00

1 --> 01

2 --> 02

and so on.

Suggestions?

Frequent Contributor
Posts: 106

Re: week function

Posted in reply to sophia_SAS

Use this, but this will be text instead of numeric .

week_function=put(week(dt,'u'),z2.);

Super User
Posts: 19,770

Re: week function

Posted in reply to sophia_SAS

If you want it displayed as 01, 02 you can apply the z2 format. If you want it as text instead, use the formula supplied above.

Frequent Contributor
Posts: 106

Re: week function

Posted in reply to sophia_SAS

As explained by Reeza above, you can also use Z2. in format if you need column as Num;

data want;

format week_function z2.;

week_function=week('01JAN2014'd,'u');

run;

Ask a Question
Discussion stats
  • 3 replies
  • 276 views
  • 0 likes
  • 3 in conversation