Help using Base SAS procedures

Year and Month

Reply
Frequent Contributor
Posts: 122

Year and Month

Hi,

I have a requirement where I need to populate a field with year and month.

eg: 201201

Any suggestions?

Respected Advisor
Posts: 3,156

Re: Year and Month

'populate a field with year and month' from what??

Suppose that your source is date variable. Although you can concatenate all the way to your target, proc format seems to have an edge:

proc format;

picture my_yearmon

         low-high='%Y%0m'(datatype=date);

run;

data test;

format a date9.;

a=date();

b=put(a,my_yearmon6.);

run;

proc print;run;

Haikuo

Frequent Contributor
Posts: 122

Year and Month

Thank you Hai.kuo!

Regular Contributor
Posts: 184

Year and Month

The YYMMN6. format should do it.

Respected Advisor
Posts: 3,156

Year and Month

Thanks for sharing! Yes, It does work! It is strange I can't find the doc, I could only locate it as informat, but not format from 9.2 online docs:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000363557.htm

Regards,

Haikuo

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