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

Hi,

 

I have the following data-set  with first three variables, and I want to create another variable month such that it represents the month and year of the date variable. Any suggestions on how to create it?

winidpermnodatemonth
111/1/2000Jan-00
111/2/2000Jan-00
111/3/2000Jan-00
11…..Jan-00
11…..Jan-00
11…..Jan-00
111/31/2000Jan-00
212/1/2000Feb-00
212/2/2000Feb-00
21….Feb-00
21…..Feb-00
212/29/2000Feb-00
1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Not sure how mabny ways there is to type this: Post test data in the form of a datastep!!!

So now lets start the guessing, is date an actual numeric date value?  If so then:

data want;
  set have;
  month=put(date,monyy.);
run;

http://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n1anshj9oarq...

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Not sure how mabny ways there is to type this: Post test data in the form of a datastep!!!

So now lets start the guessing, is date an actual numeric date value?  If so then:

data want;
  set have;
  month=put(date,monyy.);
run;

http://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n1anshj9oarq...

ballardw
Super User

For a very large number of analysis or display purposes what you propose doing may not be needed at all. If the "date" is an actual SAS date value and not character then a change of the display format for a procedure may be all that is needed. See this example:

 

data example;
   informat date mmddyy10. ;
   format date mmddyy10.;
   input date value;
datalines;
01/01/2018  123
01/23/2018  24
01/31/2018  456
02/02/2018  333
02/05/2018  6
;
run;

proc means data=example;
   class date;
   var value;
run;

proc means data=example;
   class date;
   var value;
   format date monyy5.;
run;

No additional variable was needed to get different groups for analysis, just a change of format.

 

Almost all of the analysis, grahping and reporting procedures like Report and Tabulate will honor the format for creating groups.

Also Proc Format will allow you create specific date, time or datetime appearances if you can't find a SAS supplied format that appears exactly as you want.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 824 views
  • 1 like
  • 3 in conversation