SAS, PROC FORMAT change string to numeric

1.5k views Asked by At

I want to create a format on a string variable (Monday, Tuesday, Wednesd, Thrusda, Friday) to see the result as 1 to 5, so I can sort the data. I tried sth as:

proc format;
     value days
     'Monday'=1
     'Tuesday'=2
     'Wednesd'=3
     'Thrusda'=4
     'Friday'=5
run;

In the log file, an error likes this appear:

ERROR: The quoted string 'Monday' is not acceptable to a numeric format or informat. ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a format name. ERROR 200-322: The symbol is not recognized and will be ignored.

Additional INFO

After creating the format, I will apply this in the plot, something like below:

 PROC GLM data=Newspaper;
      class Day Newspaper;
      model ad_effect = Day|Newspaper;
      **format Day days.;**
      title 'Analyze the effects of Day & Newspaper';
      title2 'Including Interaction';
 run;
 quit;
 title;

Using the Format, the the marker in the scatter plot can be showed in a order from Monday to Friday. Otherwise, the marker will be showed based on alphabetical order.

Please share your idea.

1

There are 1 answers

2
data _null_ On BEST ANSWER

You can use and INFORMAT to create a new variable by reading the day name as a number. For example.

proc format;
   invalue days
     'Monday'=1
     'Tuesday'=2
     'Wednesd'=3
     'Thrusda'=4
     'Friday'=5;
   run;
data days;
   input day:days.;
   cards;
Monday
Tuesday
Wednesd
;;;;
   run;
proc print;
   run;