BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jiasyuen
Calcite | Level 5
data base1;
set lib.base1;

run;

proc summary data=base1 nway missing;
class prd;
var gp;

run;

My prd is a set of date. I am required to extract the first 4 digits of it. For example, 202012, and I only need 2020. 

Is there any way to extract it? Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

 

data base1;
set lib.base1;
prd2=substrn(prd,1,4);
run;

View solution in original post

3 REPLIES 3
andreas_lds
Jade | Level 19

Depends on the type of prd:

  • if it is a string, use substr-function
  • if it is numeric, convert in to string and use substr
  • if you have a real date, use year-function to extract the year.
jiasyuen
Calcite | Level 5

Let say it's a string. How would I convert? Can you show me the line of code? Thank you.

Patrick
Opal | Level 21

 

data base1;
set lib.base1;
prd2=substrn(prd,1,4);
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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