Hello everyone, this might be a dumb question but here we go.
I am trying to extract a specific date information pra a column in one table into another new table. However, when i try to do that, the date information in the new table is shown as serial number. Is there any way to do this and extract only the first 9 characters aligned on the left in the column week1?
This is the code that i am using and the output that i am getting (the wrong one):
data test2; set test;
length week2 $ 10;
week2= left(week1);
run;
| week1 | week2 |
| 05JAN2018:00:00:00 | 1830729600 |
| 05JAN2018:00:00:00 | 1830729600 |
| 05JAN2018:00:00:00 | 1830729600 |
| 05JAN2018:00:00:00 | 1830729600 |
| 05JAN2018:00:00:00 | 1830729600 |
| 05JAN2018:00:00:00 | 1830729600
|
*Note: The date column in the original table is numerical and has this weirds "00:00" on it.
This is the output that i desire in the new table:
| week1 | week2 |
| 05JAN2018:00:00:00 | 05JAN2018 |
| 05JAN2018:00:00:00 | 05JAN2018 |
| 05JAN2018:00:00:00 | 05JAN2018 |
| 05JAN2018:00:00:00 | 05JAN2018 |
| 05JAN2018:00:00:00 | 05JAN2018 |
| 05JAN2018:00:00:00 | 05JAN2018 |
Thanks guys
Your code:
data test2; set test;
length week2 $ 10;
week2= left(week1);
run;
You need to replace the left function into:
- week_date = datepart(week1);
- week2 = put(week_date,date9.);
Your code:
data test2; set test;
length week2 $ 10;
week2= left(week1);
run;
You need to replace the left function into:
- week_date = datepart(week1);
- week2 = put(week_date,date9.);
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.