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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.