BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
lindamtl
Fluorite | Level 6

I have a data set, the month variable:month is CHAR7. So there is only year and month, ,shown as this format

2015-11

2015-12

I need to change them into NOV2015, DEC2015. So firstly i need change it into SAS .

I tried:

date=input(month, date7.) or other time formate, but it doesnt work.

As i need use conditional statement, so i dont want to separate them into year and month into to column, i hope they still stay in the same column.

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star
28         data want;
29           Date_Char = '2015-11';
30           Date_Num = input(strip(Date_Char) !! '-01', yymmdd10.);
31           format Date_Num date9.;
32           put _all_;
33         run;

Date_Char=2015-11 Date_Num=01NOV2015 _ERROR_=0 _N_=1
NOTE: The data set WORK.WANT has 1 observations and 2 variables.
NOTE: Compressing data set WORK.WANT increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

View solution in original post

4 REPLIES 4
SASKiwi
PROC Star
28         data want;
29           Date_Char = '2015-11';
30           Date_Num = input(strip(Date_Char) !! '-01', yymmdd10.);
31           format Date_Num date9.;
32           put _all_;
33         run;

Date_Char=2015-11 Date_Num=01NOV2015 _ERROR_=0 _N_=1
NOTE: The data set WORK.WANT has 1 observations and 2 variables.
NOTE: Compressing data set WORK.WANT increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
lindamtl
Fluorite | Level 6

it works. i added a format, so it output as NOV2015. thanks.

 

data test1;
set aa (keep=month);
date=input(strip(month)!!'-1', yymmdd10.);
format date monyy7.;
run;

Tom
Super User Tom
Super User

Note that SAS has new functions for concatenating strings. even newer than the relatively new STRIP() function.

Date_Num = input(cats(Date_Char,'-01'), yymmdd10.);
lindamtl
Fluorite | Level 6

yes, it works, i also tried. thank you~

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 4 replies
  • 332 views
  • 1 like
  • 3 in conversation