DATA Step, Macro, Functions and more

week function

Reply
Frequent Contributor
Posts: 104

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

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

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

Super User
Posts: 17,963

Re: week function

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

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
  • 272 views
  • 0 likes
  • 3 in conversation