BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
data have;
input date $20.;
cards;
21may2019
21-may-2012
21/may/2013
21-may-2014
21-may-12
12/21/2018
run;

want:
2019-05-21
2012-05-21
2013-05-21
2014-05-21
2012-05-21
2018-12-21
1 ACCEPTED SOLUTION

Accepted Solutions
rajeshalwayswel
Pyrite | Level 9

 


I found the Solution of my question: :)

data want; input date $20.; a1=put(input(date,anydtdte12.),yymmdd10.); cards; 21may2019 21-may-2012 21/may/2013 21-may-2014 21-may-12 12/21/2018 run;

View solution in original post

2 REPLIES 2
rajeshalwayswel
Pyrite | Level 9

 


I found the Solution of my question: :)

data want; input date $20.; a1=put(input(date,anydtdte12.),yymmdd10.); cards; 21may2019 21-may-2012 21/may/2013 21-may-2014 21-may-12 12/21/2018 run;
ballardw
Super User

@rajeshalwayswel wrote:

 


I found the Solution of my question: :)

data want; input date $20.; a1=put(input(date,anydtdte12.),yymmdd10.); cards; 21may2019 21-may-2012 21/may/2013 21-may-2014 21-may-12 12/21/2018 run;

I would suggest that you leave the date as a date value instead of creating a text version using the Put function and assign the format to the variable:

 

data want;
input date $20.;
a1=  input(date,anydtdte12.);
format a1 yymmdd10.;
cards;
21may2019
21-may-2012
21/may/2013
21-may-2014
21-may-12
12/21/2018
run;

Then if you need to manipulate the date such as extract values, such as the year, month, day of the year, day of the week and such then you can use an appropriate function, or increment a date, or determine the value between two dates then the functions Intnx or Intck come into play.

Also for some analysis, reporting or graphing you can change or create groups simply by changing the format

Example: (You should have the Sashelp.stocks data set available). The default format for the date variable in this data set is Date7 and represents the first stock trading day of the month.

But I want to examine the behavior of a variable by the calendar year. So

Proc means data=sashelp.stocks max min mean;
   class stock date;
   format date year4.;
   var open;
run;

Will show the maximum, minimum and mean value of the stock opening price for each calendar year in the data for each stock.

I didn't have to add any variables to create the new group.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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