Sorry, my bug.
Drop the 'then' - code should be:
len = length(strip(date_var));
select (len);
when (4) date = mdy(01,01,input(date_var,4.));
when (7) date = input('01'||date_var, date9.);
when (9) date = input(date_var,date9.);
otherwise put 'Check obs ' _N_ date_var=;
end;
If you want to output 3 files, then the following should work:
data year mmyyyy mdy;
set have;
select (length(strip(diagdate)));
when (7) output mmyyyy;
when (9) output mdy;
otherwise output year;
end;
run;
HTH,
Art, CEO, AnalystFinder.com
@PaulaC: Sorry to hear that you're still having problems. Seeing your code would definitely help as well as seeing the dates (as entered in the raw data) for the 50 people in question.
The following definitely worked for me given your sample data:
data year mmyyyy mdy; input date02 $9.; format diagdate date9.; select (length(strip(date02))); when (4) do; diagdate = mdy(01,01,input(date02,4.)); output year; end; when (7) do; diagdate = input('01'||date02, date9.); output mmyyyy; end; when (9) do; diagdate = input(date02,date9.); output mdy; end; otherwise put 'Check obs ' _N_ date02=; end; cards; 1963 1964 1970 1972 198 1980 1981 APR1993 DEC1991 FEB1995 JUL1980 MAR1993 MAY1995 NOV1973 NOV1994 OCT1979 01APR1993 01APR1997 01AUG1991 ;
Art, CEO, AnalystFinder.com
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.