BookmarkSubscribeRSS Feed
Yondori
Calcite | Level 5

Hi

I have my own dataset as follows

1111.png

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?

3 REPLIES 3
Astounding
PROC Star

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.

ballardw
Super User

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_Month=month(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);

Yondori
Calcite | Level 5

it was numeric value.

Thanks~ it worked~!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

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