Help using Base SAS procedures

How to convert best32. value or numeric value to date format?

Reply
Frequent Contributor
Posts: 122

How to convert best32. value or numeric value to date format?

Hi,

I have the following values in two files :

File 1 :

201301

201302

the values are in best32. format.

File 2:

201301

201302

the values are numeric values(8 bytes)

I would like to convert the date values in two files to date format i.e 201301 (date format). Kindly help.

Thanks

Frequent Contributor
Frequent Contributor
Posts: 83

Re: How to convert best32. value or numeric value to date format?

Are they year and month? I mean

201301 stands for JAN2013? Then I think the following codes might help.

(assume variable name- datevar and day is 1st of the month)

Data want;

set have;

     year=substr(datevar,1,4);

     month=substr(datevar,5,2);

     day=1;

     date=input(catx('/',day2,month,year), ddmmyy10.);

     format date ddmmyy10.;

     drop year month day;

run;

Super User
Super User
Posts: 6,502

Re: How to convert best32. value or numeric value to date format?

Depends on what date you mean by those 6 digit strings.

6 digit dates could be DDMMYY, MMDDYY, YYMMDD or even possible YYDDMM.  If we assume that there is a four digit year then perhaps it means YYYYMM or MMYYYY.

Values of 20 and 13 are invalid as months. So only possible interpretations are YYYYMM and YYDDMM, but the later is not likely.

So if you want to convert the number to a date then use the INPUT() function.  To display it in the same 6 digit YYYYMM format you can use the SAS format YYMMN6.

data _null_;

  x=201301;

  d=input(put(x,6.)||'01',yymmdd8.);

  format d yymmn6.;

  put x= d=;

run;

x=201301 d=201301

Frequent Contributor
Posts: 122

Re: How to convert best32. value or numeric value to date format?

Thank you all!

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