Hi, i need to help with below..i need to get only year and month form below data
Data Have Data Want
190125 201901
180512 201805
171202 201712
Is HAVE a character string or a number? If it is a number is the value 190,125 or are they actual date values that have been formatted with YYMMDD6. format?
If they are not real date values why are you sure the first one should be 2019 and not 1919 or 2119?
Are your 'have' values numeric or character?
With the assumption that "HAVE' is a numeric variable, you can apply the yymmn6. format.
@doctortimi wrote:
With the assumption that "HAVE' is a numeric variable, you can apply the yymmn6. format.
No, you can't. Dates are the number of days since 1Jan1960:
25 data _null_; 26 a = 190125; 27 put a=; 28 put a= date9.; 29 put a= yymmn6.; 30 run; a=190125 a=17JUL2480 a=248007
Thanks for the correction. I wrongly assumed that HAVE were the days since 1960.
You don't specify whether your starting value is a character string or number:
If it is a character string:
data have;
input strng $6.;
datalines;
190125
180512
171202
run;
data want;
set have;
dat=input(strng,yymmdd6.);
format dat yymmn6. ;
put (_all_) (=);
run;
If it's a number, then:
data have;
input nmbr ;
datalines;
190125
180512
171202
run;
data _null_;
set have;
dat=mdy(mod(floor(nmbr/100),100),mod(nmbr,100),2000+floor(nmbr/10000));
format dat yymmn6.;
put (_all_) (=);
run;
Note that in both cases, you have to transform the actual value. It's not just a matter of finding the right format. BTW, if you run the programs above without assigning a format to dat, you'll see the actual value (number of days after 01jan1960).
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.