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

I have a variable in the form of yymmdd, and I want to extract yymm from it without changing the date format. I konw year() and month(),but I don't know how to get year and month in one variable. thanks a lot.

1 ACCEPTED SOLUTION
7 REPLIES 7
lixuan
Obsidian | Level 7

just like this? but it didn't work.

ym=put(yymm,yymm6.);
lixuan
Obsidian | Level 7

sorry , i make a mistake. it has been resolved using the code. thank you!

lixuan
Obsidian | Level 7

but after  finished, it's  character  format instead of date format. my code :

data have;
format dt yymmdd10.;
input dt yymmdd10.;
datalines;
2016-05-21
2017-08-12
2014-03-02
;
run;

data want;
set have;
yy = put(dt,yymmn6.);
run;
Kurt_Bremser
Super User

@lixuan wrote:

but after  finished, it's  character  format instead of date format. my code :

data have;
format dt yymmdd10.;
input dt yymmdd10.;
datalines;
2016-05-21
2017-08-12
2014-03-02
;
run;

data want;
set have;
yy = put(dt,yymmn6.);
run;

A SAS data value defines a certain day. When you only have year and month, one usually uses a character variable for display, as a SAS data variable cannot be built without a day value.

If you simply assign the yymm format to your original variable, it will display the way you want to. If you do want to create a new SAS date variable, you will have to set a rule for the day that it will use "internally", and then assign the yymm format to the new variable.

Singla14
Calcite | Level 5
, I have input file having year ( let's say 2015 to 2017 YYYY) .
I am trying to fetch system year ( year(today())
And then compare year from input file to fetched year.
If matches , those rows should come in output.

If comparison for years is not working ..Have tried reading input year in chat..Integer both..But nothing working.
Can some one please help..Urgent
Kurt_Bremser
Super User

@Singla14 wrote:
, I have input file having year ( let's say 2015 to 2017 YYYY) .
I am trying to fetch system year ( year(today())
And then compare year from input file to fetched year.
If matches , those rows should come in output.

If comparison for years is not working ..Have tried reading input year in chat..Integer both..But nothing working.
Can some one please help..Urgent


Don't hijack other people's threads, start your own.

 

Post your code and the log of the whole step.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 4957 views
  • 0 likes
  • 3 in conversation