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

Hi,

Below is an example of the data I have.

 

Both A and B must be character types. 

 

I just want to assign a date format to column A so that I get output as column B. 

 

how can I do this efficiently without any warnings? Please advise. 

 

A B
20150107 2015/01/07
20150207 2015/02/07
2015 2015
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Is this what you want?

If the string in A can be interpretted as YYYYMMDD then make B have the same date printed with slash delimiters.  Otherwise just copy A to B.

data want;
  set have;
  date = input(a,??yymmdd8.);
  if not missing(date) then b=put(date,yymmdds10.);
  else b=a;
  drop date;
run;

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Is this what you want?

If the string in A can be interpretted as YYYYMMDD then make B have the same date printed with slash delimiters.  Otherwise just copy A to B.

data want;
  set have;
  date = input(a,??yymmdd8.);
  if not missing(date) then b=put(date,yymmdds10.);
  else b=a;
  drop date;
run;

 

bharath86
Obsidian | Level 7

Thank you sir.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 2 replies
  • 393 views
  • 0 likes
  • 2 in conversation