BookmarkSubscribeRSS Feed
renjithr
Quartz | Level 8

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

3 REPLIES 3
Mit
Calcite | Level 5 Mit
Calcite | Level 5

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;

Tom
Super User Tom
Super User

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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 5152 views
  • 0 likes
  • 3 in conversation