0
votes

I want to define a date format that takes the following format : 12JAN2010

I tried using this code :

    /* partie B question 2*/
    data projet.Ophtalmo_new;
    set projet.Ophtalmo_new (RENAME=(date_diagnostic=date_dia)) (RENAME=
(date_examen=date_exa));
    date_diagnostic = input (date_dia, DDMMYY10.);
    date_examen = input (date_exa, DDMMYY10.);
    format date_diagnostic date_examen date9.;
    run;

But it sends me the following syntax error :

ERROR 22-322: Syntax error, expecting one of the following: un nom, une chaƮne 
entre guillemets, ;,
          CUROBS, END, INDSNAME, KEY, KEYRESET, KEYS, NOBS, OPEN, POINT, 
_DATA_, _LAST_, _NULL_.

I'm still a sas beginner and i can't manage to get it to work properly, hope you can help, thanks.

3

3 Answers

1
votes

The syntax for data set options is a single parenthetical expression. The rename option fits within:

data-set-name ( ... options ... rename=(...) );

The syntax of the RENAME option is the following:

rename=(old-name-1=new-name-1 old-name-2=new-name-2 ...)

So the correct set statement would be

set projet.Ophtalmo_new (RENAME=(date_diagnostic=date_dia date_examen=date_exa));

Because you state your are a beginner I added this section.

The code you show indicates input of the variables originally named date_diagnostic and date_examen. If these variables are indeed character variables to start, then the input is necessary to convert from character to a SAS date (which is simply a number with special meaning). If, however, the variables were already a SAS date with a format different than the one you want, you only need to update the format of the variables (or use a FORMAT statement to change the format to use during a PROC step)

data have;
  x = '01-jan-2017'd;
  format x ddmmyy10.;
run;

* demonstrate that the permanent format of x is ddmmyy10.;
data _null_;
  put x=;
run;

* demonstrate temporary formatting of variable during step;
data _null_;
  set have;
  format x date9.;  * modify the format temporarily during execution of data _null_;
  put x=;
run;

* permanently change format of variable;
* only the dataset metadata (or header data) changes, the entire data set is NOT rewritten;
proc datasets nolist lib=work;
  modify have;
  format x date9.;
run;

* demonstrate that the permanent format of x has changed to date9.;
data _null_;
  set have;
  put x=;
run;
0
votes

I believe the issue is the RENAME statement. You can only call it once.

Change this:

set projet.Ophtalmo_new (RENAME=(date_diagnostic=date_dia)) (RENAME=
(date_examen=date_exa));

to this:

set projet.Ophtalmo_new (RENAME=(date_diagnostic=date_dia date_examen=date_exa));
0
votes

You can't rename the dates and then use those variables in your INPUT statement. They've been renamed and no longer exist, so trying to access date_dia in the INPUT function will at worst result in all missing values.

You also shouldn't use the notation of having the same data set name in your DATA and SET statement. This means once this step is run, the original data no longer exists. So you need to back up several steps and recreate your original data first before you can even fix your code. In general, this leads to errors that are harder to diagnose and fix because even if you fix your code your original data is wrong so you still think you have errors.

So, changes: 1. Change name of output data set in data statement. 2. Remove RENAME data set options. 3. Add DROP statement to remove the variables no longer desired.

/* partie B question 2*/
data projet.Ophtalmo2; 
set projet.Ophtalmo_new; 

date_diagnostic = input (date_dia, DDMMYY10.);
date_examen = input (date_exa, DDMMYY10.);
format date_diagnostic date_examen date9.;

 drop date_dia date_exa;
run;