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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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