Date to Int

Solved
Occasional Contributor
Posts: 16

Date to Int

I need to join a data set by the primary id and the month.
The month field in one table(A) is a char and the month field in the other table(B) calandar.

Table A month field is formatted like 20150301 INT
TABLE B month field is formatted like 01SEP14 DATE

HOW CAN I FORMAT THE MONTH FIELD IN TABLE A(01SEP14) TO return (20140901) INT

iVE TRIED THE BELOW
(DIDNT WORK)

DATA work.ACCTS;
SET work.ACCTS ;
MONYEARCHAR=put(firstday,z6.);
RUN;
QUIT;

Accepted Solutions
Solution
‎04-24-2015 11:41 PM
Posts: 5,529

Re: Date to Int

INT looks more like a numeric than a character variable. To get a number that looks like a date, you will need an input(put()) combination:

data test;

firstday = '01SEP14'd;

format firstday date7.;

int = input(put(firstday, yymmddn8.), 8.0);

run;

proc print; run;

PG

PG

All Replies
Posts: 1,270

Re: Date to Int

Try this to see if it works.

format month yymmddn8.;

Super User
Posts: 23,724

Re: Date to Int

You need yymmdd8. format instead of z6 format in your put statement.

If you're doing this via SQL you can do the transformation in the SQL join step.

Solution
‎04-24-2015 11:41 PM
Posts: 5,529

Re: Date to Int

INT looks more like a numeric than a character variable. To get a number that looks like a date, you will need an input(put()) combination:

data test;

firstday = '01SEP14'd;

format firstday date7.;

int = input(put(firstday, yymmddn8.), 8.0);

run;

proc print; run;

PG

PG
🔒 This topic is solved and locked.