BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sowmya12
Fluorite | Level 6
If date is 2019/un/un.how can I get 2019 or 11/un/un.from this how we can extract 11
1 ACCEPTED SOLUTION

Accepted Solutions
Amir
PROC Star

Hi @Sowmya12,

 

If the first part of your data is always the year, then the below might help (assuming your date is character, based on what you've shown).

 

The scan() function selects part of string that is separated by a specific character(s).

 

data have;
   input my_date : $char10.;

   datalines;
2019/un/un
11/un/un
;


data want;
   set have;
   
   y = scan(my_date,1,'/');
run;

 

 

Kind regards,

Amir.

View solution in original post

5 REPLIES 5
Amir
PROC Star

Hi @Sowmya12,

 

If the first part of your data is always the year, then the below might help (assuming your date is character, based on what you've shown).

 

The scan() function selects part of string that is separated by a specific character(s).

 

data have;
   input my_date : $char10.;

   datalines;
2019/un/un
11/un/un
;


data want;
   set have;
   
   y = scan(my_date,1,'/');
run;

 

 

Kind regards,

Amir.

Amir
PROC Star

Hi @Sowmya12,

 

I meant to add a length statement to give y a length of 4.

 

Kind regards,

Amir.

Kurt_Bremser
Super User

I would store year as a number with length 3. This allows years up to 8192, consumes the least space, and can be used in calculations or functions without conversion.

Amir
PROC Star

True.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 618 views
  • 0 likes
  • 3 in conversation