Dear,
I am running following program. i am not getting the out I need. please suggest. Thank you
data one;
input cmendtc_raw $11.;
datalines;
UN/Feb/2015
;
data two;
set one;
cmendtc=put(input(cmendtc_raw, ?? date11.),yymmdd10.);
if missing(cmendtc) and not missing(cmendtc_raw) then
do;
length _day1 _month1 _year1 8;
_day1 =input(scan(cmendtc_raw,1,'/','m'), ?? best32.);
_month1=month(input(scan(cmendtc_raw,2,'/','m')||'2000', ?? monyy.));
_year1 =input(scan(cmendtc_raw,3,'/','m'),?? best32.);
end;
if _day1<1 or _day1>31 then call missing(_day1);
if _month1<1 or _month1>12 then call missing(_month1);
/* valid day and year? */
if mdy(01,_day1,_year1) then cmendtc=put(_year1,z4.)||'--'||put(_day1,z2.);
/* valid month and year? */
else if mdy(_month1,01,_year1) then cmendtc=put(_year1,z4.)||'-'||put(_month1,z2.);
/* valid year? */
else if mdy(02,01,_year1) then cmendtc=put(_year1,z4.);
run;
output need:
2015-02
I am seeing a blank value " .' . The missing function is not recognizing. Please help. Thank you
Dear,
I am running following program. i am not getting the out I need. please suggest. Thank you
data one;
input cmendtc_raw $11.;
datalines;
UN/Feb/2015
;
data two;
set one;
cmendtc=put(input(cmendtc_raw, ?? date11.),yymmdd10.);
if missing(cmendtc) and not missing(cmendtc_raw) then
do;
length _day1 _month1 _year1 8;
_day1 =input(scan(cmendtc_raw,1,'/','m'), ?? best32.);
_month1=month(input(scan(cmendtc_raw,2,'/','m')||'2000', ?? monyy.));
_year1 =input(scan(cmendtc_raw,3,'/','m'),?? best32.);
end;
if _day1<1 or _day1>31 then call missing(_day1);
if _month1<1 or _month1>12 then call missing(_month1);
/* valid day and year? */
if mdy(01,_day1,_year1) then cmendtc=put(_year1,z4.)||'--'||put(_day1,z2.);
/* valid month and year? */
else if mdy(_month1,01,_year1) then cmendtc=put(_year1,z4.)||'-'||put(_month1,z2.);
/* valid year? */
else if mdy(02,01,_year1) then cmendtc=put(_year1,z4.);
run;
output need:
2015-02
I am seeing a blank value " .' . The missing function is not recognizing. Please help. Thank you
Why so complicated?
data have;
input cmendtc_raw $11.;
datalines;
UN/Feb/2015
;
run;
proc format;
value $monthrev
'Jan' = '-01'
'Feb' = '-02'
'Mar' = '-03'
/* add other months here */
other = ' '
;
run;
data want;
set have;
length cmendtc $10;
cmendtc = scan(cmendtc_raw,3,'/') !! put(scan(cmendtc_raw,2,'/'),$monthrev3.);
if substr(cmendtc_raw,1,2) ne 'UN' then cmendtc = trim(cmendtc) !! substr(cmendtc_raw,1,2);
run;
proc print data=want noobs;
run;
Result:
cmendtc_raw cmendtc UN/Feb/2015 2015-02
Or without formats;
data want (drop=mnth); length dstr $20; input dstr $; dstr=tranwrd(dstr,"UN",""); if scan(dstr,2,"/") ne "" then mnth=put(month(input(cats("01",scan(dstr,2,"/"),"2010"),date9.)),z2.); formatted=catx("-",scan(dstr,3,"/"),mnth,scan(dstr,1,"/")); datalines; UN/Feb/2016 01/Mar/2014 UN/UN/2011 ; run;
There were a lot of good hints and suggestions there.
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.
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.