DATA child_birthday;
input subject name $ year month date ;
datalines;
1001 Thomas 2000 12 15
;
run;
I want to create a new variables named as birthday_yyyymmdd from the variables year, month, and date.
For example, from the dateset, l want to create a variable 2001215.
I have tried
data child_birthday;
birthday_yymmdd=substr(year,1,4)+substr(month,1,2)+substr(date,1,2);
run;
but I am not getting anything.
Any help or comment would be appreciated.
Maria.
The reason it's not working is that you've created year, month and date as numeric whereas substr only works on character variables. If you want to create a date from individual numeric values use the mdy function like this
data want;
format birthday_yymmdd date9.;
set child_birthday;
birthday_yymmdd=mdy(month,date,year);
run;
The reason it's not working is that you've created year, month and date as numeric whereas substr only works on character variables. If you want to create a date from individual numeric values use the mdy function like this
data want;
format birthday_yymmdd date9.;
set child_birthday;
birthday_yymmdd=mdy(month,date,year);
run;
Not sure if this is what you want to do.
Try this....
data WANT;
set HAVE;
call symput=("DT_SUFFIX",cats("BIRTHDAY_",YEAR,MONTH,DATE));
BIRTHDAY_=MDY(MONTH,DATE,YEAR);
format birthday_ date9.;
run;
proc datasets lib=work;
modify want;
rename birthday_=&dt_suffix.;
run;
quit;
Hope this helps.
data want;
set child_birthday;
format birthday_yymmdd yymmdd10.;
birthday_yymmdd =mdy(month,date,year);
run;
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.
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.