BookmarkSubscribeRSS Feed
Smitha9
Fluorite | Level 6

Hi,

I have a dataset

DOB (character)

07/1980

03/1978

10/1982

I want this to change to numeric. And a separate month and year column added.

DOB(numeric)           Month                 Year

07/1980                     July                    1980

03/1978                     March                1978

10/1982                    October              1982

 

thanks in advance

 

 

1 REPLY 1
ballardw
Super User

One way:

data have;
   input dob $;
datalines;
07/1980
03/1978
10/1982
;

data want;
  set have;
  dobnum = input(dob,anydtdte.);
  format dobnum mmyys7.;
  /*redundant*/
  month = put(dobnum,monname. -L);
  year = year(dobnum);
run;

The Input creates a date value using a very flexible approach for many date layouts. In this case it will assume that the day of the month is 1.

The Month and Year are redundant because you can get them easily from the Dobnum variable by applying a format if needed. The -L in the Put is the left justify the value so that there aren't any leading spaces in the month text.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 187 views
  • 0 likes
  • 2 in conversation