BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
edison83
Obsidian | Level 7

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;

 

 

week1week2
  05JAN2018:00:00:001830729600
  05JAN2018:00:00:001830729600
  05JAN2018:00:00:001830729600
  05JAN2018:00:00:001830729600
  05JAN2018:00:00:001830729600
  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:

week1week2
  05JAN2018:00:00:0005JAN2018
  05JAN2018:00:00:0005JAN2018
  05JAN2018:00:00:0005JAN2018
  05JAN2018:00:00:0005JAN2018
  05JAN2018:00:00:0005JAN2018
  05JAN2018:00:00:0005JAN2018

 

Thanks guys

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

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.);

 

View solution in original post

2 REPLIES 2
Shmuel
Garnet | Level 18

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.);

 

edison83
Obsidian | Level 7
Thanks, it worked! Sorry for the late reply

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 836 views
  • 0 likes
  • 2 in conversation