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-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!

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
  • 1614 views
  • 0 likes
  • 3 in conversation