BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
thomask23
Fluorite | Level 6

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;
PLEASE HELP.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

View solution in original post

3 REPLIES 3
stat_sas
Ammonite | Level 13

Try this to see if it works.

format month yymmddn8.;

Reeza
Super User

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. 

PGStats
Opal | Level 21

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

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 935 views
  • 3 likes
  • 4 in conversation