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.
You can use the yymm format in a put statement.
You can use the yymm format in a put statement.
just like this? but it didn't work.
ym=put(yymm,yymm6.);
sorry , i make a mistake. it has been resolved using the code. thank you!
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;
@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 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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.