Programming the statistical procedures from SAS

Substr Functions

Occasional Contributor
Posts: 16

Substr Functions


I have my own dataset as follows


Now Birthday is like yyyymmdd (e.g. 20011011)

and I want to make it seperately like

B_Year     B_Month     B_Day

2001          10               11

But, how can I do this?

I tried to make it using substr function but, it doesn't work.

maybe because it is numeric format or somehing. but, Is there any way that I can extract it separtely?

Super User
Posts: 5,701

Re: Substr Functions

You'll have to tell us more about the variable BIRTHDAY.

Is it character or numeric?

If numeric, does it actually take on the value that you have displayed, or is that a formatted value based on the scale that SAS normally uses for dates?

Once we know those answers, the programming will be easy.

Super User
Posts: 11,758

Re: Substr Functions

Is the date a SAS date value, possibly with a yymmddn8. format? If so then the date functions would be appropriate

B_year= year(birthday);


B_Day = day(birthday).

if you want a text result and the birthday is a simple number then something like this may work:

b_year = substr(put(birthday,f8.0),1,4);

b_month= substr(put(birthday,f8.0),5,2);

b_day = substr(put(birthday,f8.0),7,2);

Occasional Contributor
Posts: 16

Re: Substr Functions

it was numeric value.

Thanks~ it worked~!

Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation