preloadfmt not working and no apparent error or warnig in SAS

77 Views Asked by At

I need to sort the Academic Year descending. Since this is not a numeric variable, I decided to use the preloadfmt to make sure the table follows this format -> Ideal formatting

However, the preloadfmt is not working and is not showing any warning or error in the log. The only thing I see in the log is: "NOTE: Format $LOADE is already on the library WORK.FORMATS. NOTE: Format $LOADE has been output." I don't think this has something to do.

I get this as a result of the code below Result from the code below Any idea how I can get the ideal result?

/*This is the code I'm using:*/ 


proc format; 

value $LOADE
'FT' = 'FT'
'PT' = 'PT';

value $LEVEL
'First time Freshmen' = '1st'
'Other Freshmen' = '1st'
'Sophomores' = '2nd'
'Juniors' = '3rd'
'Seniors' = '4rd';

value $Academic
'2023-24'='2023-24'
'2022-23'='2022-23'
'2021-22'='2021-22'
'2020-21'='2020-21'
'2019-20'='2019-20';

run;


proc tabulate data=step3;
TITLE1 "Hisotircal Enrollment by load and level";
where pmajr='SYST';
class Academic_Year load level_description / preloadfmt;
Table (Academic_Year*load), level_description all=total/ printmiss misstext='0';*/ norow nocol nopercent nocum;
format load $loade. Academic_Year $Academic. level_description $level.;
run;
1

There are 1 best solutions below

0
Richard On BEST ANSWER

In PROC FORMAT VALUE statememt use option NOTSORTED
In PROC TABULATE CLASS statement add option ORDER=FORMATTED

Two of the formats in your code can be removed because they are redundant and do not perform any transformation.

Example:

data have (label='All students were harmed in making this fake data') ;
  call streaminit(2024) ;
  do academYear = '2023-24', '2022-23', '2021-22', '2020-21' ;
  do enrollYear = 'Frosh', 'Soph', 'Jr', 'Sr' ;
    do _n_ = 1 to rand('integer', 500,750) ;
      load = ifc (rand('uniform') < 0.33, 'PT', 'FT') ;
      OUTPUT ;
    end ;
  end ; end ;
run ;

proc format ;
  value $eYear (notsorted) 
    'Frosh' = '1st'
    'Soph'  = '2nd'
    'Jr'    = '3rd'
    'Sr'    = '4th'
  ;
run ;

ods html file='report.html' style=plateau ;

title 'Raw' ;
proc tabulate data=have ;
  class academYear enrollYear load ;
  table academYear*load,enrollYear ;
run ;

title '(NOTSORTED) -- ORDER=FORMATTED, PRELOADFMT and PRINTMISS' ;
proc tabulate data=have ;
  class academYear / descending ;
  class load ; 
  class enrollYear / order=formatted preloadfmt ; 
  table academYear*load,enrollYear / printmiss ;
  format enrollYear $eYear. ;
run ;

ods html close ;

enter image description here