BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PaulaC
Fluorite | Level 6
It finally worked with the addition of the date02=strip(date02); statement. Thanks to both you and @art297. I really appreciate both of your help with this.
PaulaC
Fluorite | Level 6
Thank you very much. I will definitely try that. Appreciate your help.
PaulaC
Fluorite | Level 6
I just tried and I got an error message with the "then". Please find the message from the log below:
123 data diagfix1;
124 set disease;
125 len = length(strip(date02));
126 select (len);
127 when (4) then diagdate = mdy(01,01,input(date02,4.));
----
180
128 when (7) then diagdate = input('01'||date02, date9.);
----
180
129 when (9) then diagdate = input(date02,date9.);
----
180
ERROR 180-322: Statement is not valid or it is used out of proper order.

130 otherwise put 'Check obs ' _N_ date02=;
131 end;
132 diagtime=intck('year',diagdate,daterand);
133 run;

NOTE: The SAS System stopped processing this step because of errors.

Thanks.
Shmuel
Garnet | Level 18

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;
art297
Opal | Level 21

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
Fluorite | Level 6
Thank you
art297
Opal | Level 21

@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

 

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
  • 21 replies
  • 2685 views
  • 2 likes
  • 3 in conversation